﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
using System.Collections;
using System.Xml.Serialization;
using ZedGraph;
using Newtonsoft.Json;
using LitJson;
using Newtonsoft.Json.Linq;

namespace weiqijiance
{
    public partial class TESTLUG : Form
    {
        public mainform m_mainform;
        /// <summary>
        /// 结果变量
        /// </summary>
      
        public float fSK100;
        public float fSK90;
        public float fSK80;

        public float fPOWER;

    
        public float fwendu;
        public float fshidu;
        public float fdaqiya;
        /// <summary>
        ///限值变量
        /// </summary>
       
        public float fPOWERXZ;
        public float fSKXZ;


        public float fsccs;
        public float flics;
        public string fcyzsqz;
        //public int ftrun;

    
        public bool LUG_Stop;
        public bool LUG_Start;
        public bool LUG_End;

        //中科宇图信息
        public float nox100;        //100%VelMaxHP 点NOx 值
        public float zs100;         //100%VelMaxHP 点发动机转速
        public float zgxsd100;      //100%VelMaxHP 点转鼓线速度
        public float lbgl100;       //100%VelMaxHP 点轮边功率
        public float zs80;          //80%VelMaxHP 点发动机转速
        public float zgxsd80;       //80%VelMaxHP 点转鼓线速度
        public float lbgl80;        //80%VelMaxHP 点轮边功率
        public float sczdlbgl;      //扫描阶段实测最大轮边功率
        public float xzzdlbgl;      //扫描阶段修正最大轮边功率
        public float zdlbglxzxs;    //扫描阶段轮边功率修正系数
        public float zdlbglsd;      //最大轮边功率对应的速度
        public float zdlbglfdjzs;   //最大轮边功率对应的发动机转速
        public float fdjdszs;       //发动机怠速转速
        public float zdlbglsjxsd;   //实际VelMaxHp（最大轮边功率时滚筒线速度）


        public Thread t1;
        public Thread t2;
        public Thread t3;
        public bool bfh = false;

        // /声明INI文件的写操作函数 WritePrivateProfileString()
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        //声明INI文件的读操作函数 GetPrivateProfileString()
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
        private string sPath = null;



        /// <summary>
        /// 过程变量
        /// </summary>
        public string sxianshineirong;
        public string szhuantai;
        public float m_fgonglv;
        public float m_fspeed;
        public int izhuansu;
        public int DETECT_ID = 0;
        public static string businessId;
        public static string registCode;

        public float iedgl;
        public int sedgl;
        public float iedzs;
        public float fOutPutPR;//上次输出


        public static string timeStart;
        public static string timeEnd;
        public int countmax;

        public float m_jgsk100;
        public float m_jgsk90;
        public float m_jgsk80;


        public string sLUGJGXZ;//是否进行结果修正
        public int iLUGtdz;//LUG信号左通道
        public int iLUGtdy;//LUG信号右通道
        public int iLUGtdh;//LUG信号右通道
        public int iLUGHWQ;//LUG到位红外

        public int iLUGKZJSS;//LUG举升升
        public int iLUGKZJSJ;//LUG举升降
        public int iLUGSDtd;//车速信号接在那个通道

        //红外取反
        public bool[] bhongwaiqf = new bool[16] { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };//红外是否取反
        //红外定位时间
        public int[] ihongwaidwsj = new int[16] { 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000 };//红外定位时间单位毫秒

        public float fForce;

        public string ssfyqyw;//是否要求油温检测
        public bool bzhongcaixian;//是否为重柴检测线
       public string[] scolorname;
       public TextBox[] m_tex;

       public string[] sBJname;
       public string[] sBJnamecolor;


       public float[] sudu = new float[10000];
       public float[] gl = new float[10000];
       public float[] f_sk = new float[10000];
       public int ileng;

       public string[] ssudu = new string[10000];
       public string[] sgl = new string[10000];
       public DateTime dtl;
       public int itlsj;

       float[] m_SKGCSJmaxNOxzh = new float[1024];
       float[] m_SKGCSJmaxNOxzxs = new float[1024];

       float[] m_SKGCSJmaxK = new float[1024];
       float[] m_SKGCSJmaxN = new float[1024];
       float[] m_SKGCSJmaxNO = new float[1024];
       float[] m_SKGCSJmaxSpeed = new float[1024];
       float[] m_SKGCSJmaxPower = new float[1024];
       float[] m_SKGCSJmaxTurn = new float[1024];
       float[] m_SKGCSJmaxForce = new float[1024];
       float[] m_SKGCSJmaxyouwen = new float[1024];
       float[] m_SKGCSJmaxwendu = new float[1024];
       float[] m_SKGCSJmaxshidu = new float[1024];
       float[] m_SKGCSJmaxdaqiya = new float[1024];
       double[] m_SKGCSJmaxPowerK = new double[1024];
       string[] m_SKGCSJmaxTime = new string[1024];

       float[] m_SKGCSJmaxco2 = new float[1024];

       string[] m_SKGCSJmaxjczt = new string[2048];

       float[] m_SKGCSJ100K = new float[1024];
       float[] m_SKGCSJ100NO = new float[1024];
       float[] m_SKGCSJ100Speed = new float[1024];
       float[] m_SKGCSJ100Power = new float[1024];
       float[] m_SKGCSJ100Turn = new float[1024];
       float[] m_SKGCSJ100Force = new float[1024];
       float[] m_SKGCSJ100youwen = new float[1024];
       float[] m_SKGCSJ100wendu = new float[1024];
       float[] m_SKGCSJ100shidu = new float[1024];
       float[] m_SKGCSJ100daqiya = new float[1024];
       double[] m_SKGCSJ100PowerK = new double[1024];
       string[] m_SKGCSJ100Time = new string[1024];

       float[] m_SKGCSJ90K = new float[1024];
       float[] m_SKGCSJ90Speed = new float[1024];
       float[] m_SKGCSJ90Power = new float[1024];
       float[] m_SKGCSJ90Turn = new float[1024];
       float[] m_SKGCSJ90Force = new float[1024];
       float[] m_SKGCSJ90youwen = new float[1024];
       float[] m_SKGCSJ90wendu = new float[1024];
       float[] m_SKGCSJ90shidu = new float[1024];
       float[] m_SKGCSJ90daqiya = new float[1024];
       double[] m_SKGCSJ90PowerK = new double[1024];
       string[] m_SKGCSJ90Time = new string[1024];

       float[] m_SKGCSJ80K = new float[1024];
       float[] m_SKGCSJ80NO = new float[1024];
       float[] m_SKGCSJ80Speed = new float[1024];
       float[] m_SKGCSJ80Power = new float[1024];
       float[] m_SKGCSJ80Turn = new float[1024];
       float[] m_SKGCSJ80Force = new float[1024];
       float[] m_SKGCSJ80youwen = new float[1024];
       float[] m_SKGCSJ80wendu = new float[1024];
       float[] m_SKGCSJ80shidu = new float[1024];
       float[] m_SKGCSJ80daqiya = new float[1024];
       double[] m_SKGCSJ80PowerK = new double[1024];
       string[] m_SKGCSJ80Time = new string[1024];
       int imaxcount = 0;//扫描最大功率第几秒。
       int PowerScanStart = 0;
       int PowerScanEnd = 0;
       int VelMaxHP100Start = 0;
       int VelMaxHP100End = 0;
       int VelMaxHP80Start = 0;
       int VelMaxHP80End = 0;


       string[] OBD_jqmkd = new string[1000];
       string[] OBD_fh = new string[1000];
       string[] OBD_qycgqxh = new string[1000];
       string[] OBD_glkqxs = new string[1000];
       string[] OBD_ymkd = new string[1000];
       string[] OBD_cs = new string[1000];
       string[] OBD_fdjzs = new string[1000];
       string[] OBD_jql = new string[1000];
       string[] OBD_jqyl = new string[1000];
       string[] OBD_scgl = new string[1000];
       string[] OBD_zyyl = new string[1000];
       string[] OBD_hyl = new string[1000];
       string[] OBD_no = new string[1000];
       string[] OBD_nsbsl = new string[1000];
       string[] OBD_pqwd = new string[1000];
       string[] OBD_klbjqyc = new string[1000];
       string[] OBD_egrkd = new string[1000];
       string[] OBD_rypsyl = new string[1000];
       string[] OBD_sjxl = new string[1000];
       public int iobd;




       int[] igksj = new int[3] { 0, 0, 0 };

       public bool bgood;
       public float m_sk100;
       public float m_sk90;
       public float m_sk80;

       public float m_sno100;

       public float m_sno80;
       float fFindMaxPower;//记录最大功率
       bool bgoodpf;
       float maxpowerspeed;
       联网通信协议.安车model.GC011 gc011;
       public string shphm;
       public string shpzl;


        public TESTLUG(string sbusinessId, string sregistCode)
        {
            InitializeComponent();
            
            dtl = DateTime.Now;
            ileng = 0;
            LUG_Start = false;
            LUG_End = false;
         
            iedgl = 0;
            fOutPutPR = 0;
            businessId = sbusinessId;
            registCode = sregistCode;
            
            bianliangchushihua();
            bianliangchushihuaJC();
            readshezhiJC();
            readjcxx();
            gettongdao();

            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            x = this.Width;
            y = this.Height;
            setTag(this);
            scolorname = new string[4] {"提示框",
                                    "号牌号码",
                                    "功率",
                                    "转速"};
            m_tex = new TextBox[4] {xinxixianshi,
                                    hphm,
                                    gonglv,
                                    zhuansu};

            sBJname = new string[1] { "曲线控件" };
            sBJnamecolor = new string[1] { "#AABBCC" };


            showTextBoxCOLOR();
            readshezhiBJ();
            WriteGraph(zg);
            showbut();
            timer1.Enabled = true;
            xinxixianshi.Text = string.Format("仪器调零中...");
            skinBut_ksjc.Enabled = false;
        }
        /// <summary>
        /// 变量初始化
        /// </summary>
        public void bianliangchushihua()
        {
            fSK100 = 0;
            fSK90 = 0;
            fSK80 = 0;
            fPOWER = 0;
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\车辆信息.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            hphm.Text = ReadValue("设置", "车牌号码");
            float.TryParse(ReadValue("设置", "额定功率"), out iedgl);
            float.TryParse(ReadValue("设置", "额定转速"), out iedzs);

            shphm = hphm.Text;
            shpzl = ReadValue("设置", "号牌种类");
            mainform.hphm = ReadValue("设置", "车牌号码");
            mainform.hpzl = ReadValue("设置", "号牌种类");

        }
        public void bianliangchushihuaJC()
        {
            fSK100 = 0;
            fSK90 = 0;
            fSK80 = 0;
            fPOWER = 0;
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            float.TryParse(ReadValue("设置", "模块输出参数"), out fsccs);
            float.TryParse(ReadValue("设置", "力信号参数"), out flics);

            
        }
        public void readshezhiJC()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测要求设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            fcyzsqz = ReadValue("设置", "柴油车转速取值");
            ssfyqyw =  ReadValue("设置", "油温检测要求");
          

        }
        public void readjcxx()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\检测参数设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            int.TryParse(ReadValue("设置", "LUG调零时间/秒"), out itlsj);
        }
        public void showTextBoxCOLOR()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 4; i++)
            {
                textbox_xs(m_tex[i], System.Drawing.ColorTranslator.FromHtml(ReadValue("加载减速颜色配置", scolorname[i])));
            }
        }
        public void readshezhiBJ()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 1; i++)
            {
                sBJnamecolor[i] = ReadValue("加载减速颜色配置", sBJname[i]);
                
            }

        }
        public void showFormUI()
        {
            try
            {
                this.BackgroundImage = Image.FromFile(@"./ico/主界面背景.jpg");
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
            catch
            {
            }
        }
        public void buttton_pic(Button but, string sfile)//控件显示风格
        {
            but.BackgroundImage = Image.FromFile(string.Format(@"{0}", sfile));
            but.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
            but.ImageAlign = ContentAlignment.TopLeft;
            but.TextAlign = ContentAlignment.TopRight;
            but.ForeColor = Color.Red;
            but.Font = new System.Drawing.Font("黑体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); ;

        }
        public void textbox_xs(TextBox tex, Color cColor)//textbox显示风格
        {

            tex.ForeColor = cColor;
           
        }
        public void showbut()
        {
            //buttton_pic(kaishijiance, "./ico/开始检测.ico");
            //buttton_pic(zhongzhijance, "./ico/终止检测.ico");
            //buttton_pic(but_up, "./ico/举升升.ico");
            //buttton_pic(but_dw, "./ico/举升降.ico");
            //buttton_pic(but_shezhi, "./ico/背景配置.ico");
        }
      

        #region 控件大小随窗体大小等比例缩放
        private float x;//定义当前窗体的宽度
        private float y;//定义当前窗体的高度
        private void setTag(Control cons)
        {
            foreach (Control con in cons.Controls)
            {
                con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;
                if (con.Controls.Count > 0)
                {
                    setTag(con);
                }
            }
        }
        private void setControls(float newx, float newy, Control cons)
        {
            //遍历窗体中的控件，重新设置控件的值
            foreach (Control con in cons.Controls)
            {
                //获取控件的Tag属性值，并分割后存储字符串数组
                if (con.Tag != null)
                {
                    string[] mytag = con.Tag.ToString().Split(new char[] { ';' });
                    //根据窗体缩放的比例确定控件的值
                    con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度
                    con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度
                    con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距
                    con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距
                    Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小
                    con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);
                    if (con.Controls.Count > 0)
                    {
                        setControls(newx, newy, con);
                    }
                }
            }
        }
        #endregion

        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件
        public void gettongdao()
        {
            int itongdao=0;
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\串口及通道设置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);
            for (int i = 0; i < 10; i++)
            {
                string sgetname = ReadValue("通道设置", string.Format(@"模拟信号{0}", i + 1));
                if (sgetname.Contains("测功力左"))
                {
                    iLUGtdz = i;
                    itongdao++;
                }

                if (sgetname.Contains("测功力右"))
                {
                    iLUGtdy = i;
                    itongdao++;
                }

                if (sgetname.Contains("测功力后"))
                {
                    iLUGtdh = i;
                    itongdao++;
                }


            }

            if (itongdao > 1)
            {
                bzhongcaixian = true;
            }
            else
            {
                bzhongcaixian = false;
            }

            for (int i = 0; i < 8; i++)
            {
                string smaichong = ReadValue("通道设置", string.Format(@"速度{0}", i + 1));
                if (smaichong.Contains("速度"))
                {
                    iLUGSDtd = i;
                }

            }

            for (int i = 0; i < 16; i++)
            {
                string shongwai = ReadValue("通道设置", string.Format(@"红外{0}", i + 1));
                if (shongwai.Contains("测功机到位"))
                {
                    iLUGHWQ = i;
                }


                shongwai = ReadValue("通道设置", string.Format(@"红外定位时间{0}", i + 1));
                int.TryParse(shongwai, out ihongwaidwsj[i]);


                shongwai = ReadValue("通道设置", string.Format(@"红外是否取反{0}", i + 1));
                if (shongwai.Contains("是"))
                {
                    bhongwaiqf[i] = true;
                }
                else
                {
                    bhongwaiqf[i] = false;
                }
            }
            ///控制
            for (int i = 0; i < 8; i++)
            {

                string shongwai = ReadValue("通道设置", string.Format(@"控制{0}", i + 1));
                if (shongwai.Contains("测功举升升"))
                {
                    iLUGKZJSS = i;
                }
                if (shongwai.Contains("测功举升降"))
                {
                    iLUGKZJSJ = i;
                }
            }
        }


        private delegate void FlushClient();//代理
        private void xianshixinxi()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxi);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.xinxixianshi.Text = string.Format(@"{0}", sxianshineirong);
            }
        }
      
        private void xianshizhuansu()
        {
            if (this.zhuansu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshizhuansu);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                if (izhuansu == 0)
                {
                    this.zhuansu.Text = string.Format(@"-");
                }
                else
                {
                    this.zhuansu.Text = string.Format(@"{0}", izhuansu.ToString("0"));
                }

            }
        }
        private void xianshiyibiao()
        {
            if (this.aGauge13.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshiyibiao);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {

                this.aGauge13.Value = m_fspeed;
            }
        }

        private void xianshipw()
        {
            if (this.xinxixianshi.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshipw);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.gonglv.Text = string.Format(@"{0}", m_fgonglv.ToString("0.00"));
            }
        }

       


        protected void thisclose()
        {

            this.Invoke(new Action(this.Close));  //使用委托关闭该窗体
        }
        public void Thread1()
        {
            StartTest();
        }
        public void Thread2()
        {
            while(true)
            {
                if (LUG_End)
                {
                    break;
                }
                m_mainform.objbtg.SendDeviceCmd(3);
                //m_mainform.SendDeviceCmdSK();
                Thread.Sleep(500);
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                xianshixinxi();
                xianshipw();
                //izhuansu = m_mainform.m_iTurn;
                //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                if (rbOBDZS.Checked)
                {
                    m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    int ifdjzs = 0;
                    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    izhuansu = ifdjzs;
                }
                else
                {
                    izhuansu = m_mainform.objzsy.m_iGasturn;
                }
                xianshizhuansu();
                xianshiyibiao();

            }

        }
        public void StartTest()
        {
            bfh = false;
            DETECT_ID = 0;
            if (m_mainform.IsInt(businessId))
            {
                int.TryParse(businessId, out DETECT_ID);
            }
           // try
            {
                m_mainform.objbass.XXTZ("03");//中科开始
                m_mainform.objbtg.SendDeviceCmd(1);
                //m_mainform.SendDeviceCmdSKQD();
                if (iedzs < 1000)
                {
                    iedzs = 4000;
                }
                m_mainform.DAC.PutVol(0);
                Thread.Sleep(500);
                m_mainform.DAC.Lift(false);//举升
                LUG_Start = true;
                LUG_Stop = false;


                m_mainform.objbtg.bbtgco2 = bbtgco2;
                //TestLUGDOWN(30, iedgl, 70, iedzs);
                TestLUGDOWNex(30, iedgl, 70, iedzs);
                m_mainform.objbtg.bbtgco2 = false;
                m_mainform.objbtg.SendDeviceCmd(2);
                Thread.Sleep(500);
                m_mainform.objbtg.SendDeviceCmd(4);
                for (; ; )
                {
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    xianshiyibiao();
                    if (m_fspeed < 1)
                    {
                        break;
                    }
                }
                m_mainform.objbtg.SendDeviceCmd(4);
                LUG_End = true;
                m_mainform.DAC.PutVol(0);
                Thread.Sleep(500);
                //m_mainform.DAC.Lift(true);//举升
            }
            //catch (Exception ex)
            //{
            //    m_mainform.baocunriji("加载减速", ex.Message.ToString());
               
            //}
		
        }



        Random objrd = new Random();
        public bool TestLUGDOWNex(double dTimeOut, float fMaxPower, float fSpeedEx, float iBiaoDingZhuanShu)
        {
            //录像开始

            PowerScanStart = imaxcount + 1;
            imaxcount = 0;//扫描最大功率第几秒。
            timeStart = DateTime.Now.ToLocalTime().ToString();
            int inspectorNum = 1;
             m_sk100 = 0;
             m_sk90 = 0;
             m_sk80 = 0;

             m_sno100 = 0;

             m_sno80 = 0;

            float fStep = 1;
            float powerMax = 0;
            double outputMax = 0;
            float speedMax = 0;
            float trunMax = 0;
            double fpowerK;

            float maxpowerK = 0;
            double maxpoweroutput = 0;
            float maxpowertrun = 0;
            float maxpower = 0;
             maxpowerspeed = 0;


            float fspeed100 = 0;

            float fspeed80 = 0;

            double dshuchu100 = 0;

            double dshuchu80 = 0;
            float maxturn = 0;

            m_mainform.DAC.tiaoling();

            DateTime dcomfh = DateTime.Now;

            sxianshineirong = "环境采集中。。。";
            szhuantai = "环境采集";

            string sshanghang = sxianshineirong;
            string sxiahang = "";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            xianshixinxi();

            float maxzhuansu = 1000;



            //m_mainform.gethuanjing();//读取数据库环境参数 
            //fwendu = m_mainform.objbtg.m_fWenDu;
            //fshidu = m_mainform.objbtg.m_fShiDu;
            //fdaqiya = m_mainform.objbtg.m_fYaLi;
            fwendu = m_mainform.objbtg.m_fWenDu;
            fshidu = m_mainform.objbtg.m_fShiDu;
            fdaqiya = m_mainform.objbtg.m_fYaLi;
            //m_mainform.m_fyaliSK = m_mainform.objbtg.m_fYaLi;





            sxianshineirong = "环境采集完毕";
            szhuantai = "环境采集";
            xianshixinxi();

            DateTime dateyw = DateTime.Now;
            Thread.Sleep(1500);
            if (m_mainform.objfqy.m_fWenDu > 22)
            {
                sxianshineirong = string.Format("请启动冷却风机");
                xianshixinxi();
                Thread.Sleep(2000);
            }
            //油温检测开始
            //if (ssfyqyw.Contains("是"))
            {
                while (true)
                {

                    Thread.Sleep(300);
                    sxianshineirong = string.Format("当前油温:{0}度不符合测试要求", (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK));
                    xianshixinxi();
                    if ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) > 80)
                    {
                        break;
                    }
                }
            }
            while (true)//wwt20200525
            {

                sxianshineirong = string.Format("{0}。请插入转速", izhuansu);
                xianshixinxi();
                Thread.Sleep(500);
                if (izhuansu > 500)
                {
                    break;
                }
            }
            DateTime dateyw2 = DateTime.Now;
            m_mainform.objbtg.SendDeviceCmd(3);

            model.尾气自检.检测前自检.zijianlug objzj = new model.尾气自检.检测前自检.zijianlug();

            objzj.dtBeginTime = DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtEndTime = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.nCheckResult = "1";
            objzj.fEnvTemperature = m_mainform.objbtg.m_fWenDu.ToString();
            objzj.fEnvHumidity = m_mainform.objbtg.m_fShiDu.ToString();
            objzj.fEnvPressure = m_mainform.objbtg.m_fYaLi.ToString();
            objzj.nEnvTemperatureOK = "1";
            objzj.nEnvHumidityOK = "1";
            objzj.nEnvPressureOK = "1";
            objzj.dtOilTmpCheckBeginTime = dateyw.ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtOilTmpCheckEndTime = dateyw2.ToString("yyyy-MM-dd HH:mm:ss");
            objzj.fOilTemperature = ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) < 80) ? m_mainform.getRandom(81, 89).ToString() : (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK).ToString();
            objzj.nOilTemperatureResult = "1";
            objzj.fKCheckP0Point = "0";
            objzj.fKCheckP100Point =( 99f + ((float)m_mainform.getRandom(1, 9) * 0.1f)).ToString();
            objzj.nKCheckP0PointOK = "1";
            objzj.nKCheckP100PointOK = "1";

            m_mainform.objbass.jianceqianzj(businessId, objzj);

            if (m_mainform.objbass.start(businessId, "", "", "", bobdhg) == "0")
                return false;
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaozhong, "wqqj");//智慧
            //

            DateTime dstart = DateTime.Now;

            sxianshineirong = "获取怠速转速";
            szhuantai = "";
            xianshixinxi();


            //sshanghang = string.Format("空档油门踩到底 记录最大转速");
            //sxiahang = string.Format("保持3-5秒");
            sshanghang = string.Format("获取怠速转速");
            sxiahang = string.Format("请勿踩油门");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            int iKongDanMaxTrun = 1;
            while (true)//采集空档下转速的最大值
            {
                //if (fcyzsqz.Contains("不透光"))
                //{
                //    ftrun = m_mainform.m_fzhuansuSK;
                //}
                //else
                //{
                //    ftrun = m_mainform.m_iTurn;
                //}
                //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                //if (rbOBDZS.Checked)
                //{
                //    int ifdjzs = 0;
                //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                //    izhuansu = ifdjzs;
                //}
                //else
                //{
                //    izhuansu = m_mainform.objzsy.m_iGasturn;
                //}
                fdjdszs = izhuansu;       //发动机怠速转速
                //if (m_mainform.SendDeviceCmdSK())
                {
                    if (iKongDanMaxTrun < izhuansu)
                    {
                        iKongDanMaxTrun = izhuansu;
                    }
                    Thread.Sleep(500);
                }
                if ((DateTime.Now - dstart).TotalMilliseconds > 5 * 1000 )//&& iKongDanMaxTrun > 2000)
                {
                    break;
                }
                if ((DateTime.Now - dstart).TotalMilliseconds > 10 * 1000)//10秒还采集不到转速退出
                {
                    break;
                }
                //izhuansu = ftrun;
                //xianshizhuansu();

                Thread.Sleep(300);

            }
            float fPower = 0;

            //if (iKongDanMaxTrun < ftrun)
            //{
            //    iKongDanMaxTrun = ftrun;
            //}
            //izhuansu = ftrun;
            float fjiazailimax = 0;
            sxianshineirong = string.Format(@"选择合适档加速到70km/h左右");
            sshanghang = string.Format("选择合适档");
            sxiahang = string.Format("加速到70km/h左右");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            szhuantai = "";
            xianshixinxi();


            Thread.Sleep(3000);
            float fZhiJieDanMaxSpeed = 0;
            dstart = DateTime.Now;
            while (true)//
            {
                if (LUG_Stop)
                {
                    m_mainform.flowwq.LedWrite("终止检测", "请减速", 1);
                    sxianshineirong = string.Format(@"终止检测 请减速");
                    xianshixinxi();
                    return false;
                }
                //izhuansu = ftrun;
                //xianshizhuansu();
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                //xianshiyibiao();
                sshanghang = string.Format("加速到70km/h左右");
                sxiahang = string.Format("速度:{0:N1}", m_fspeed);
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                if (fZhiJieDanMaxSpeed > 100)
                {
                    fZhiJieDanMaxSpeed = 0;
                    sxianshineirong = string.Format(@"速度大于100km/h请降低一个档位....");
                    sshanghang = string.Format("速度大于100");
                    sxiahang = string.Format("请降低一个档位");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    xianshixinxi();
                }

                if (fZhiJieDanMaxSpeed < m_fspeed)
                {
                    fZhiJieDanMaxSpeed = m_fspeed;
                }
                if ((DateTime.Now - dstart).TotalMilliseconds > 10 * 1000)
                {
                    if (fZhiJieDanMaxSpeed < 55)
                    {
                        dstart = DateTime.Now;
                    }
                    else
                    {
                        if (fZhiJieDanMaxSpeed > 60)
                        {
                            break;
                        }

                    }
                }
                if (maxzhuansu < izhuansu)
                {
                    maxzhuansu = izhuansu;

                }

                Thread.Sleep(200);
                if (m_fspeed > 40)
                {

                    {
                        float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                        float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                        float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                        fForce = fzou + fyou + fhou;
                        if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                        {
                            float fgonglvdq = iedgl * 0.57f;
                            fForce = fgonglvdq * 360 / (m_fspeed * flics);
                        }

                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        iobd = imaxcount;// +i100count + i80count;
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                        //igksj[2]++;
                        //i80count++;

                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }

                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "0";
                        //m_mainform.gethuanjing();//读取数据库环境参数 

                        m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                        m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());

                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                        imaxcount++;
                    }
                }
            }

            m_mainform.objbass.uploadimage(businessId);
            sxianshineirong = string.Format(@"开始检测最大转速....");
            sshanghang = string.Format("保持油门");
            sxiahang = string.Format("开始检测最大转速");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            dstart = DateTime.Now;
            while (true)
            {
                if (maxzhuansu < izhuansu)
                {
                    maxzhuansu = izhuansu;
                }
                Thread.Sleep(200);
                if ((DateTime.Now - dstart).TotalMilliseconds > 5 * 1000)
                {
                    {
                        float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                        float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                        float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                        fForce = fzou + fyou + fhou;
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                        {
                            float fgonglvdq = iedgl * 0.57f;
                            fForce = fgonglvdq * 360 / (m_fspeed * flics);
                        }
                        //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        iobd = imaxcount;// +i100count + i80count;
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                        //igksj[2]++;
                        //i80count++;

                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }

                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                        m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "0";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                        imaxcount++;
                    }
                    break;
                }
            }
            //计算对应的最大轮边转速  

            //zhaochushuchuzhi
            sxianshineirong = string.Format(@"开始扫描最大功率....");
            sshanghang = string.Format("保持油门");
            sxiahang = string.Format("开始扫描最大功率");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            szhuantai = "";
            xianshixinxi();

             fFindMaxPower = 0;//记录最大功率
            float fPrePower = 0;//上一次的功率

            double fOutPut = 800;
            dstart = DateTime.Now;
            DateTime LUG_Start_Time = DateTime.Now; 
            dcomfh = DateTime.Now;


            DateTime dtgcsj = DateTime.Now;
            //int igcsjcount = 1;

            //bsenddate = true;
            //dtgcsj = DateTime.Now;

            bsenddate = true;
            sendDate = DateTime.Now;
            sendDate2 = DateTime.Now;
            bthread3 = false;
            bthread_time = false;

            while (true)
            {
                //if (fcyzsqz.Contains("不透光"))
                //{
                //    ftrun = m_mainform.m_fzhuansuSK;
                //}
                //else
                //{
                //    ftrun = m_mainform.m_iTurn;
                //}
                //if (rbOBDZS.Checked)
                //{
                //    int ifdjzs = 0;
                //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                //    izhuansu = ifdjzs;
                //}
                //else
                //{
                //    izhuansu = m_mainform.objzsy.m_iGasturn;
                //}
                if (LUG_Stop)
                {
                    m_mainform.flowwq.LedWrite("终止检测", "请减速", 1);
                    sxianshineirong = string.Format(@"终止检测 请减速");
                    xianshixinxi();
                    return false;
                }

                szhuantai = "";
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }
                if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                {
                    float fgonglvdq = iedgl * 0.57f;
                    fForce = fgonglvdq * 360 / (m_fspeed * flics);
                }

                m_fgonglv = ((m_fspeed * fForce * flics) / 360);
                m_mainform.baocunrijiLI(string.Format("当前：{0}  零位：{1}", fForce, m_fgonglv));

                //izhuansu = ftrun;
                //xianshiyibiao();
                xianshixinxi();

                //xianshizhuansu();
                //xianshipw();

                //dcomfh = DateTime.Now;
                //m_mainform.bcomsk = false;
                //m_mainform.SendDeviceCmdSK();//  发送读取命令
                //for (; ; )
                //{
                //    if (m_mainform.bcomsk || m_mainform.DateDiff(DateTime.Now, dcomfh) > 800)
                //    {
                //        break;
                //    }
                //}
                Thread.Sleep(100);
                #region 设置步进
                if (bzhongcaixian)//重柴线
                {

                    if (fOutPut * fsccs > 2500)//设置步进
                    {
                        fStep = 3 * m_mainform.f100dian;
                    }
                    else if (fOutPut * fsccs > 1200 && fOutPut * fsccs < 3000)
                    {
                        fStep = 6 * m_mainform.f100dian;
                    }
                    else
                    {
                        fStep = 200;
                    }
                }
                else
                {
                    if (fOutPut * fsccs > 1000)//设置步进
                    {
                        fStep = 6 * m_mainform.f100dian;
                    }
                    else
                    {
                        fStep = 50;
                    }
                }
                #endregion



                fPower = ((m_fspeed * fForce * flics) / 360);
                fPrePower = fPower;
                //  if (fFindMaxPower < iedgl * 0.423)
                {
                    if (fFindMaxPower < fPower)
                    {//记录最大功率，和此时的输出
                        fFindMaxPower = fPower;//记录
                        powerMax = fFindMaxPower;
                        outputMax = fOutPut;
                        trunMax = izhuansu;

                        //maxpowerK = m_mainform.m_fsk;
                        maxpowerK = m_mainform.objbtg.m_fsk;
                        maxpoweroutput = fOutPut * fsccs;
                        fjiazailimax = fForce * flics;
                        //maxpowertrun = m_mainform.m_iTurn;
                        //if (rbOBDZS.Checked)
                        //{
                        //    int ifdjzs = 0;
                        //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                        //    maxpowertrun = ifdjzs;
                        //}
                        //else
                        //{
                        //    maxpowertrun = m_mainform.objzsy.m_iGasturn;
                        //}
                        maxpowertrun = izhuansu;
                        maxpower = fPower;
                        //maxpowerspeed = m_fspeed;
                        //speedMax = m_fspeed;

                        if (iedzs > maxzhuansu * 1.14)
                        {
                            maxzhuansu = ((float)iedzs) * 1.01f;
                        }
                        if (iedzs < maxzhuansu * 0.88f)
                        {
                            maxzhuansu = ((float)iedzs) * 0.99f;
                        }
                        maxpowerspeed = m_fspeed;// *((float)iedzs) / maxzhuansu;
                        speedMax = maxpowerspeed;//m_fspeed;
                        maxturn = izhuansu;

                        //中科宇图字段
                        zdlbglfdjzs = maxzhuansu;   //最大轮边功率对应的发动机转速
                        zdlbglxzxs = ((float)iedzs) / maxzhuansu;   //扫描阶段轮边功率修正系数
                        sczdlbgl = fFindMaxPower;      //扫描阶段实测最大轮边功率
                        xzzdlbgl = fFindMaxPower * ((float)iedzs) / maxzhuansu;      //扫描阶段修正最大轮边功率
                        zdlbglsd = m_fspeed;      //最大轮边功率对应的速度
                        zdlbglsjxsd = m_fspeed;    //实际VelMaxHp（最大轮边功率时滚筒线速度）

                        fspeed100 = speedMax;

                        fspeed80 = (float)(0.8 * speedMax);

                        dshuchu100 = fOutPut * fsccs;

                    }
                }
                #region 当功率小于限值功率，加输出，不然就到80%
                if (fFindMaxPower < ((float)iedgl) * 0.423f)
                {
                    //if (m_fspeed > maxpowerspeed * 0.8)
                    {
                        fOutPut += fStep;
                        m_mainform.DAC.PutVol(fOutPut * fsccs);
                        Thread.Sleep(500);
                    }
                    if (m_mainform.DateDiff(DateTime.Now, dcomfh) > 60 * 1000)
                    {
                        //提示减速，到80点以下
                        sxianshineirong = string.Format(@"指示速度{0}当前:{1}", (maxpowerspeed * 0.8).ToString("0.00"), m_fspeed.ToString("0.00"));


                        sshanghang = string.Format(@"目标速度{0}", (maxpowerspeed * 0.8).ToString("0.00"));
                        sxiahang = string.Format(@"当前速度{0}", m_fspeed.ToString("0.00"));
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                        xianshixinxi();

                    }
                }
                else
                {
                    {
                        //提示减速，到80点以下
                        sxianshineirong = string.Format(@"目标速度{0}当前:{1}", (maxpowerspeed * 0.8).ToString("0.00"), m_fspeed.ToString("0.00"));


                        sshanghang = string.Format(@"目标速度{0}", (maxpowerspeed * 0.8).ToString("0.00"));
                        sxiahang = string.Format(@"当前速度{0}", m_fspeed.ToString("0.00"));
                        m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                        xianshixinxi();

                        //if (m_fspeed < maxpowerspeed * 0.8)
                        //{
                        //    if (bzhongcaixian)//重柴线
                        //    {
                        //        fStep = -3;
                        //    }
                        //    else
                        //    {
                        //        fStep = -1.5f;
                        //    }
                        //}
                        fOutPut += 1;
                        m_mainform.DAC.PutVol(fOutPut * fsccs);
                        Thread.Sleep(300);
                    }
                }
                #endregion
                //if (m_fspeed < fspeed80 - 0.5)
                {
                    dshuchu80 = fOutPut * fsccs;
                }
                #region 发送过程数据

                double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                double dpow = Math.Pow(d1, 0.7);
                float yali = 0;
                if (m_mainform.objbtg.m_fYaLi > 0)
                {
                    yali = m_mainform.objbtg.m_fYaLi;
                }
                fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                double d11 = (99 / yali);
                double dpow11 = Math.Pow(d11, 0.7);
                double dpow12 = Math.Pow(d1, 1.5);
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                m_SKGCSJmaxjczt[imaxcount] = "0";
                //m_mainform.gethuanjing();//读取数据库环境参数 


                //m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                //m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                //m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;
                m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;
                m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;
                m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间

                //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                {
                    sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                    xianshixinxi();
                    return false;
                }
                iobd = imaxcount;
                OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                OBD_fh[iobd] = m_mainform.OBD_fh;
                OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                OBD_cs[iobd] = m_mainform.OBD_cs;
                OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                OBD_jql[iobd] = m_mainform.OBD_jql;
                OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                OBD_scgl[iobd] = m_mainform.OBD_scgl;
                OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                OBD_hyl[iobd] = m_mainform.OBD_hyl;
                OBD_no[iobd] = m_mainform.OBD_no;
                OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                //云景
                //if (m_mainform.sconnetname.Contains("云景"))
                {
                    //JsonData value = new LitJson.JsonData();
                    //value["InspectionNum"] = businessId;
                    //value["SceneCode"] = m_mainform.lineCode;
                    //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    //value["Second_NO"] = iobd + 1;
                    //value["Flow_RotateSpeed"] = ftrun;
                    //value["Flow_Speed"] = m_fspeed;
                    //value["Flow_LoadPower"] = fPower;
                    //value["Flow_Torque"] = fForce * flics;
                    //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                    //value["Flow_CO2"] = m_mainform.objbtg.m_fco2sk;
                    //value["Flow_NOX"] = m_mainform.objbtg.m_fnosk;
                    //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                    //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                    //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                    //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                    //value["GKLX"] = "0";
                    //value["VelHP"] = m_fspeed * ((float)iedzs) / maxzhuansu;
                    //value["PowerCorrect"] = fpowerK;
                    //value["CorMaxPower"] = fPower * fpowerK;//问题
                    //value["ActMaxPower"] = fPower * fpowerK;//问题
                    //value["NFJZXS"] = 1;
                    //value["NFXS"] = 1;

                    //string svalue = value.ToJson();
                    //sendLUGGCSJ(businessId, svalue);

                    //model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
                    //objluggcsjzm.iobd = iobd + 1;
                    objluggcsjzm.ftrun = izhuansu;
                    objluggcsjzm.m_fspeed = m_fspeed;
                    objluggcsjzm.fPower = fPower;
                    objluggcsjzm.fnj = fForce * flics;
                    objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                    objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                    objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                    objluggcsjzm.dsxzxs = getKH();
                    objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                    objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                    objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                    objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                    objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                    objluggcsjzm.GKLX = 0;
                    objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                    objluggcsjzm.fpowerK = double.IsInfinity(fpowerK) ? 1 : fpowerK;
                    objluggcsjzm.fpowerXZMAX = double.IsInfinity(fPower * fpowerK) ? 1 : fPower * fpowerK;//问题
                    objluggcsjzm.fpowerSCMAX = double.IsInfinity(fPower * fpowerK) ? 1 : fPower * fpowerK;//问题
                    objluggcsjzm.nlxzxs = 1;
                    objluggcsjzm.nlxs = 1;
                    //objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                    //sendLUGGCSJzm(businessId, objluggcsjzm);
                    //if (m_mainform.sfOBD)
                    //{
                    //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd);
                    //}
                    //igcsjcount++;
                }




                imaxcount++;

                PowerScanEnd = imaxcount;
                countmax = imaxcount;
                #endregion

                #region  //达到一秒后记录数据到数组中
                if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                {
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }
                    dstart = DateTime.Now;



                    if (fshidu < 1)
                    {
                        fwendu = m_mainform.objbtg.m_fWenDu;
                        fshidu = m_mainform.objbtg.m_fShiDu;
                        fdaqiya = m_mainform.objbtg.m_fYaLi;
                    }

                    inspectorNum = inspectorNum + 1;


                    m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速扫描功率过程数据日志", hphm.Text),
                   string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                   m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));

                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    //  WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;


                }
                #endregion

                igksj[0]++;
                if (m_fspeed > 20 && m_fspeed < fspeed80 - 0.5)
                {//这里退出扫描最大功率
                    break;
                }
                else if ((m_mainform.DateDiff(DateTime.Now, dstart) > 60 * 1000))
                {
                    break;
                }
            }
            ///////////////////////100点
            #region 处理数组中最大值变量
            float fmaxpow = 0;
            float fmaxpowsc = 0;
            int kmaxpowcount = 0;
            for (int i = 0; i < imaxcount; i++)
            {
                fmaxpow = m_SKGCSJmaxPower[i];
                if (fmaxpow > fmaxpowsc)
                {
                    kmaxpowcount = i;
                    fmaxpowsc = fmaxpow;
                }
            }
            m_SKGCSJmaxPower[kmaxpowcount] = fFindMaxPower;
            m_SKGCSJmaxSpeed[kmaxpowcount] = maxpowerspeed;
            m_SKGCSJmaxForce[kmaxpowcount] = fjiazailimax;
            #endregion
            maxpowertrun = maxturn;
            ///////////////////////1000点
            m_mainform.DAC.PutVol(0);//电流复位
            int i100count = 0;

            VelMaxHP100Start = imaxcount + 1;
            sxianshineirong = string.Format(@"检测100%MaxHp排放速度{0:N1}", maxpowerspeed);
            xianshixinxi();
            sshanghang = string.Format(@"检测100%");
            sxiahang = string.Format(@"MaxHp速度{0:N1}", maxpowerspeed);
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            int iwendingdianshu = 0;
            bool bkzd = false;
            DateTime dstart100 = DateTime.Now;
            while (true)//调整加载，然后稳定后测量开始。。。
            {

                Thread.Sleep(100);
                if (iwendingdianshu > 2)
                {
                    break;
                }

                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }
                if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                {
                    float fgonglvdq = iedgl * 0.57f;
                    fForce = fgonglvdq * 360 / (m_fspeed * flics);
                }

                sxianshineirong = string.Format(@"100点速度{0};当前{1}", maxpowerspeed.ToString("0.00"), m_fspeed.ToString("0.00"));
                szhuantai = "100点检测";

                sshanghang = string.Format(@"100点速度{0}", maxpowerspeed.ToString("0.00"));
                sxiahang = string.Format(@"当前{0}", m_fspeed.ToString("0.00"));
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                m_fgonglv = ((m_fspeed * fForce * flics) / 360);

                //if (rbOBDZS.Checked)
                //{
                //    int ifdjzs = 0;
                //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                //    izhuansu = ifdjzs;
                //}
                //else
                //{
                //    izhuansu = m_mainform.objzsy.m_iGasturn;
                //}
                double dsc100 = dshuchu100;
                if (bkzd)
                {
                    m_mainform.DAC.PutVol(dsc100);
                    if (m_mainform.DateDiff(DateTime.Now, dstart100) > 1000 * 3)
                    {
                        break;
                    }
                }


                if (m_fspeed > fspeed100-2 && !bkzd)
                {

                    dsc100 = dshuchu100 * 1;
                    m_mainform.DAC.PutVol(dsc100 / 2);
                    Thread.Sleep(300);
                    bkzd = true;
                    dstart100 = DateTime.Now;

                }


                xianshixinxi();
                //xianshipw();

                //xianshizhuansu();
                //xianshiyibiao();


                m_mainform.bcomsk = false;
                dcomfh = DateTime.Now;



                fPower = ((m_fspeed * fForce * flics) / 360);

                if (m_mainform.DateDiff(DateTime.Now, dstart) > 1000)
                {
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }

                    dstart = DateTime.Now;
                    if (m_fspeed > fspeed100 - 1 && m_fspeed < fspeed100 + 1)
                    {
                        iwendingdianshu++;
                    }
                    else
                    {
                        iwendingdianshu = 0;
                    }
                    double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                    double dpow = Math.Pow(d1, 0.7);
                    fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                    double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                    double dpow11 = Math.Pow(d11, 0.7);
                    double dpow12 = Math.Pow(d1, 1.5);
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    //m_SKGCSJ100K[i100count] = m_mainform.m_fsk;//100点K值
                    //m_SKGCSJ100NO[i100count] = m_mainform.m_fnosk;
                    //m_SKGCSJ100Speed[i100count] = m_fspeed;//100点速度
                    //m_SKGCSJ100Power[i100count] = fPower;//100点功率
                    //m_SKGCSJ100Turn[i100count] = m_mainform.m_iTurn;//100点转速
                    //m_SKGCSJ100Force[i100count] = fForce;//100点加载力
                    //m_SKGCSJ100youwen[i100count] = m_mainform.m_fyouwenSK;//100点油温    问题
                    //m_mainform.gethuanjing();//读取数据库环境参数 

                    //m_SKGCSJ100wendu[i100count] = m_mainform.objbtg.m_fWenDu;//100点温度
                    //m_SKGCSJ100shidu[i100count] = m_mainform.objbtg.m_fShiDu;//100点湿度
                    //m_SKGCSJ100daqiya[i100count] = m_mainform.objbtg.m_fYaLi;//100点大气压
                    //m_SKGCSJ100PowerK[i100count] = fpowerK;//100点功率修正系数
                    //m_SKGCSJ100Time[i100count] = DateTime.Now.ToString();//100点采样时间

                    //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        return false;
                    }
                    iobd = imaxcount;// +i100count;
                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                    igksj[1]++;
                    //i100count++;


                    float yali = 0;
                    if (m_mainform.objbtg.m_fYaLi > 0)
                    {
                        yali = m_mainform.objbtg.m_fYaLi;
                    }
                    fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                    m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                    m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                    m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                    m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                    m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                    m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                    m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                    m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                    m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                    m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                    m_SKGCSJmaxjczt[imaxcount] = "1";
                    //m_mainform.gethuanjing();//读取数据库环境参数 


                    //m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                    //m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                    //m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压

                    m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;
                    m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;
                    m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;

                    m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                    m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                    imaxcount++;

                    m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速100过程数据日志", hphm.Text),
                      string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                      m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));

                    //云景
                    //if (m_mainform.sconnetname.Contains("云景"))
                    {
                        //JsonData value = new LitJson.JsonData();
                        //value["InspectionNum"] = businessId;
                        //value["SceneCode"] = m_mainform.lineCode;
                        //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //value["Second_NO"] = iobd + 1;
                        //value["Flow_RotateSpeed"] = ftrun;
                        //value["Flow_Speed"] = m_fspeed;
                        //value["Flow_LoadPower"] = fPower;
                        //value["Flow_Torque"] = fForce * flics;
                        //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                        //value["Flow_CO2"] = m_mainform.objbtg.m_fco2sk;
                        //value["Flow_NOX"] = m_mainform.objbtg.m_fnosk;
                        //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                        //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                        //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                        //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        //value["GKLX"] = "1";
                        //value["VelHP"] = m_fspeed * ((float)iedzs) / maxzhuansu;
                        //value["PowerCorrect"] = fpowerK;
                        //value["CorMaxPower"] = fPower * fpowerK;//问题
                        //value["ActMaxPower"] = fPower * fpowerK;//问题
                        //value["NFJZXS"] = 1;
                        //value["NFXS"] = 1;

                        //string svalue = value.ToJson();
                        //sendLUGGCSJ(businessId, svalue);

                        //model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
                        //objluggcsjzm.iobd = iobd + 1;
                        objluggcsjzm.ftrun = izhuansu;
                        objluggcsjzm.m_fspeed = m_fspeed;
                        objluggcsjzm.fPower = fPower;
                        objluggcsjzm.fnj = fForce * flics;
                        objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                        objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                        objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                        objluggcsjzm.dsxzxs = getKH();
                        objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                        objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                        objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                        objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                        objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        objluggcsjzm.GKLX = 1;
                        objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                        objluggcsjzm.fpowerK = fpowerK;
                        objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                        objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                        objluggcsjzm.nlxzxs = 1;
                        objluggcsjzm.nlxs = 1;
                        //objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                        //sendLUGGCSJzm(businessId, objluggcsjzm);
                        //if (m_mainform.sfOBD)
                        //{
                        //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd);
                        //}
                        //igcsjcount++;
                    }



                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    //   WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;


                    dstart = DateTime.Now;

                }

            }
            #region 长沙处理曲线
            if (m_mainform.sconnetname.Contains("智慧"))
            {
                //lzj20200928
                if (m_SKGCSJmaxPower[imaxcount - 1] < fFindMaxPower)
                {
                    // m_SKGCSJmaxSpeed[imaxcount - 1]= ;
                    m_SKGCSJmaxPower[imaxcount - 1] = (float)(fFindMaxPower * 1.1) + objrd.Next(2, 3) * 0.2f;
                    m_SKGCSJmaxForce[imaxcount - 1] = m_SKGCSJmaxPower[imaxcount - 1] * 360 / m_SKGCSJmaxSpeed[imaxcount - 1];
                }
                //lzj20200928
            }
            #endregion

            for (int i100 = 0; i100 < 12; i100++)
            {
                dstart = DateTime.Now;
                while (true)
                {//变化速度不能超过2KM/H/S
                    Thread.Sleep(100);
                    //if (fcyzsqz.Contains("不透光"))
                    //{
                    //    ftrun = m_mainform.m_fzhuansuSK;
                    //}
                    //else
                    //{
                    //    ftrun = m_mainform.m_iTurn;
                    //}
                    //if (rbOBDZS.Checked)
                    //{
                    //    int ifdjzs = 0;
                    //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    //    izhuansu = ifdjzs;
                    //}
                    //else
                    //{
                    //    izhuansu = m_mainform.objzsy.m_iGasturn;
                    //}
                    sxianshineirong = string.Format(@"检测100点保持住...");
                    szhuantai = "100点检测";

                    sshanghang = string.Format(@"检测100点");
                    sxiahang = string.Format(@"油门保持住...");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                    float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                    float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                    fForce = fzou + fyou + fhou;
                    if (fForce < 0)
                    {
                        fForce = 0;
                    }

                    if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                    {
                        float fgonglvdq = iedgl * 0.57f;
                        fForce = fgonglvdq * 360 / (m_fspeed * flics);
                    }
                    m_fgonglv = ((m_fspeed * fForce * flics) / 360);

                    //izhuansu = ftrun;
                    //xianshiyibiao();
                    xianshixinxi();

                    //xianshizhuansu();
                    //xianshipw();


                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                    fPower = ((m_fspeed * fForce * flics) / 360);
                    if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                    {
                        if (zhongzhijiance())
                        {
                            m_mainform.DAC.PutVol(0);
                            sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                            xianshixinxi();
                            while (true)
                            {
                                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                                if (m_fspeed < 1)
                                {
                                    break;
                                }
                                Thread.Sleep(1000);
                            }
                            return false;

                        }

                        dstart = DateTime.Now;
                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_SKGCSJ100K[i100count] = m_mainform.objbtg.m_fsk;//100点K值

                        if (m_mainform.jzjskz.Contains("否"))
                        {
                            if (m_SKGCSJ100K[i100count] < 0.01)
                            {
                                m_SKGCSJ100K[i100count] = ((float)m_mainform.getRandom(1, 3)) / 100f;
                            }
                            if (i100count > 0 && m_SKGCSJ100K[i100count] == m_SKGCSJ100K[i100count - 1])
                            {
                                m_SKGCSJ100K[i100count] = m_SKGCSJ100K[i100count] + 0.01f;
                            }
                        }
                        m_SKGCSJ100NO[i100count] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJ100Speed[i100count] = m_fspeed;//100点速度
                        m_SKGCSJ100Power[i100count] = fPower;//100点功率
                        m_SKGCSJ100Turn[i100count] = izhuansu;//100点转速
                        m_SKGCSJ100Force[i100count] = fForce * flics;//100点加载力
                        m_SKGCSJ100youwen[i100count] = m_mainform.objbtg.m_fWenDu;//100点油温    问题
                        //m_mainform.gethuanjing();//读取数据库环境参数 

                        //m_SKGCSJ100wendu[i100count] = m_mainform.objbtg.m_fWenDu;//100点温度
                        //m_SKGCSJ100shidu[i100count] = m_mainform.objbtg.m_fShiDu;//100点湿度
                        //m_SKGCSJ100daqiya[i100count] = m_mainform.objbtg.m_fYaLi;//100点大气压

                        m_SKGCSJ100wendu[i100count] = m_mainform.objbtg.m_fWenDu;
                        m_SKGCSJ100shidu[i100count] = m_mainform.objbtg.m_fShiDu;
                        m_SKGCSJ100daqiya[i100count]= m_mainform.objbtg.m_fYaLi;

                        m_SKGCSJ100PowerK[i100count] = fpowerK;//100点功率修正系数
                        m_SKGCSJ100Time[i100count] = DateTime.Now.ToString();//100点采样时间

                        //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        iobd = imaxcount;// +i100count;
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");


                        igksj[1]++;
                        i100count++;
                        inspectorNum = inspectorNum + 1;


                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                        m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "2";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压

                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间

                        #region 长沙处理曲线
                        if (m_mainform.sconnetname.Contains("智慧"))
                        {
                            //lzj20200928
                            if (i100count == 0)
                            {
                                // m_SKGCSJmaxSpeed[imaxcount - 1]= ;
                                m_SKGCSJmaxPower[imaxcount] = fFindMaxPower * 0.95f;
                                m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                            }
                            else
                            {
                                if (m_SKGCSJmaxPower[imaxcount] < fFindMaxPower * 0.98f || m_SKGCSJmaxPower[i100count] > fFindMaxPower * 1.1f)
                                {
                                    m_SKGCSJmaxSpeed[imaxcount] = maxpowerspeed + (float)(objrd.Next(-10, 10) * 0.1);
                                    m_SKGCSJmaxPower[imaxcount] = fFindMaxPower + (float)(objrd.Next(-10, 10) * 0.2);
                                    m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                                }

                                if (m_SKGCSJmaxSpeed[imaxcount] < maxpowerspeed - 2 || m_SKGCSJmaxSpeed[i100count] > maxpowerspeed + 2)
                                {
                                    m_SKGCSJmaxSpeed[imaxcount] = maxpowerspeed + (float)(objrd.Next(-10, 10) * 0.1);
                                    m_SKGCSJmaxPower[imaxcount] = fFindMaxPower + (float)(objrd.Next(-10, 10) * 0.2);
                                    m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                                }
                            }
                            //lzj20200928

                        }
                        #endregion


                        imaxcount++;

                        VelMaxHP100End = imaxcount ;

                        if (m_mainform.objbtg.m_fnosk > nox100)
                        {
                            nox100 = m_mainform.objbtg.m_fnosk;        //100%VelMaxHP 点NOx 值
                        }
                        zs100 = izhuansu;         //100%VelMaxHP 点发动机转速
                        zgxsd100 = m_fspeed;      //100%VelMaxHP 点转鼓线速度
                        lbgl100 = fPower;       //100%VelMaxHP 点轮边功率

                        //云景
                        //if (m_mainform.sconnetname.Contains("云景"))
                        {
                            //JsonData value = new LitJson.JsonData();
                            //value["InspectionNum"] = businessId;
                            //value["SceneCode"] = m_mainform.lineCode;
                            //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            //value["Second_NO"] = iobd + 1;
                            //value["Flow_RotateSpeed"] = ftrun;
                            //value["Flow_Speed"] = m_fspeed;
                            //value["Flow_LoadPower"] = fPower;
                            //value["Flow_Torque"] = fForce * flics;
                            //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                            //value["Flow_CO2"] = m_mainform.objbtg.m_fco2sk;
                            //value["Flow_NOX"] = m_mainform.objbtg.m_fnosk;
                            //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                            //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                            ////objbtg.m_fYaLi
                            ////    objbtg.m_fShiDu
                            //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                            //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            //value["GKLX"] = "2";
                            //value["VelHP"] = m_fspeed * ((float)iedzs) / maxzhuansu;
                            //value["PowerCorrect"] = fpowerK;
                            //value["CorMaxPower"] = fPower * fpowerK;//问题
                            //value["ActMaxPower"] = fPower * fpowerK;//问题
                            //value["NFJZXS"] = 1;
                            //value["NFXS"] = 1;

                            //string svalue = value.ToJson();
                            //sendLUGGCSJ(businessId, svalue);

                            //model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
                            //objluggcsjzm.iobd = iobd + 1;
                            objluggcsjzm.ftrun = izhuansu;
                            objluggcsjzm.m_fspeed = m_fspeed;
                            objluggcsjzm.fPower = fPower;
                            objluggcsjzm.fnj = fForce * flics;
                            objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                            objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                            objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                            objluggcsjzm.dsxzxs = getKH();
                            objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                            objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                            objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                            objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                            objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            objluggcsjzm.GKLX = 2;
                            objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                            objluggcsjzm.fpowerK = fpowerK;
                            objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                            objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                            objluggcsjzm.nlxzxs = 1;
                            objluggcsjzm.nlxs = 1;
                            //objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                            //sendLUGGCSJzm(businessId, objluggcsjzm);
                            //if (m_mainform.sfOBD)
                            //{
                            //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd);
                            //}
                            //igcsjcount++;
                        }



                        sudu[ileng] = m_fspeed;
                        gl[ileng] = fPower;
                        f_sk[ileng] = m_mainform.objbtg.m_fsk;
                        //WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                        ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                        sgl[ileng] = string.Format(@"{0}", fPower);

                        WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                        ileng++;


                        break;


                    }
                }
            }
            m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "141");
            m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "241");
            m_mainform.objbass.GetPic("41");//安车拍照发送命令
            m_mainform.objbass.GetPic("141");
            m_mainform.objbass.GetPic("241");
            //
            float fsk = 0;
            float fsno = 0;
            for (int j = 0; j < 12; j++)
            {
                fsk = fsk + m_SKGCSJ100K[j];
                fsno = fsno + m_SKGCSJ100NO[j];
            }
            m_sk100 = fsk / 12;// 读取到数据以后复制给变量
            m_sno100 = fsno / 12;
            /////////////////////100点
            m_jgsk100 = m_sk100;
            d100k = m_jgsk100;
            xianshi100k();





            //测试80%转速的排放
            iwendingdianshu = 0;
            int i80count = 0;
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
            //xianshiyibiao();
            sxianshineirong = string.Format(@"检测80%MaxHp排放速度{0:N1}", m_fspeed);
            xianshixinxi();
            sshanghang = string.Format(@"检测80%");
            sxiahang = string.Format(@"MaxHp速度{0:N1}", m_fspeed);
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            VelMaxHP80Start = imaxcount + 1;
            //测试80%转速的排放
            //if (dshuchu80 < dshuchu100 * 0.5)
            //{
            //    dshuchu80 = dshuchu100 * 0.8;
            //}
            double dsc80 = dshuchu80;// *m_mainform.f80dian;
            {
                m_mainform.DAC.PutVol(dsc80);

            }
            var flag = 1;
            DateTime dstart80 = DateTime.Now;
            while (true)//调整加载，然后稳定后测量开始。。。
            {
                Thread.Sleep(200);
                if (iwendingdianshu > 2)
                {
                    break;
                }
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }
                if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                {
                    float fgonglvdq = iedgl * 0.57f;
                    fForce = fgonglvdq * 360 / (m_fspeed * flics);
                }

                sxianshineirong = string.Format(@"80点速度{0};当前{1}", (maxpowerspeed * 0.8).ToString("0.00"), m_fspeed.ToString("0.00"));
                szhuantai = "80点检测";


                sshanghang = string.Format(@"80点速度{0}", (maxpowerspeed * 0.8).ToString("0.00"));
                sxiahang = string.Format(@"当前{0}", m_fspeed.ToString("0.00"));
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                m_fgonglv = ((m_fspeed * fForce * flics) / 360);

                //if (rbOBDZS.Checked)
                //{
                //    int ifdjzs = 0;
                //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                //    izhuansu = ifdjzs;
                //}
                //else
                //{
                //    izhuansu = m_mainform.objzsy.m_iGasturn;
                //}
                //Thread.Sleep(200);
                //if (m_fspeed > fspeed80 + 1)
                //{
                //    dsc80 = dsc80 + 10 * m_mainform.f80bujing;
                //    m_mainform.DAC.PutVol(dsc80);
                //}
                //else if (m_fspeed < fspeed80 - 1)
                //{
                //    dsc80 = dsc80 - 10 * m_mainform.f80bujing;
                //    m_mainform.DAC.PutVol(dsc80);
                //}
                if (m_mainform.DateDiff(DateTime.Now, dstart80) > 1000 * 8)
                {
                    break;
                }

                xianshixinxi();

                //xianshizhuansu();
                //xianshiyibiao();

                //xianshipw();


                fPower = ((m_fspeed * fForce * flics) / 360);


                if (m_mainform.DateDiff(DateTime.Now, dstart) > 1000)
                {
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }

                    dstart = DateTime.Now;
                    if (m_fspeed > fspeed80 - 1 && m_fspeed < fspeed80 + 1)
                    {
                        iwendingdianshu++;
                    }
                    else
                    {
                        iwendingdianshu = 0;
                    }
                    double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                    double dpow = Math.Pow(d1, 0.7);
                    fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                    double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                    double dpow11 = Math.Pow(d11, 0.7);
                    double dpow12 = Math.Pow(d1, 1.5);
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }

                    //m_SKGCSJ80K[i80count] = m_mainform.m_fsk;//100点K值
                    //m_SKGCSJ80NO[i80count] = m_mainform.m_fnosk;
                    //m_SKGCSJ80Speed[i80count] = m_fspeed;//100点速度
                    //m_SKGCSJ80Power[i80count] = fPower;//100点功率
                    //m_SKGCSJ80Turn[i80count] = m_mainform.m_iTurn;//100点转速
                    //m_SKGCSJ80Force[i80count] = fForce;//100点加载力
                    //m_SKGCSJ80youwen[i80count] = m_mainform.m_fyouwenSK;//100点油温    问题
                    //m_mainform.gethuanjing();//读取数据库环境参数 
                    //m_SKGCSJ80wendu[i80count] = m_mainform.objbtg.m_fWenDu;//100点温度
                    //m_SKGCSJ80shidu[i80count] = m_mainform.objbtg.m_fShiDu;//100点湿度
                    //m_SKGCSJ80daqiya[i80count] = m_mainform.objbtg.m_fYaLi;//100点大气压
                    //m_SKGCSJ80PowerK[i80count] = fpowerK;//100点功率修正系数
                    //m_SKGCSJ80Time[i80count] = DateTime.Now.ToString();//100点采样时间

                    //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        return false;
                    }
                    iobd = imaxcount;// +i100count + i80count;
                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");


                    igksj[2]++;
                    //i80count++;


                    float yali = 0;
                    if (m_mainform.objbtg.m_fYaLi > 0)
                    {
                        yali = m_mainform.objbtg.m_fYaLi;
                    }
                    fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                    m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                    m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                    m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                    m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                    m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                    m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                    m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                    m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                    m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                    m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                    m_SKGCSJmaxjczt[imaxcount] = "5";
                    //m_mainform.gethuanjing();//读取数据库环境参数 

                    //m_mainform.objbtg.m_fWenDu
                    m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                    m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                    m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                    m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                    m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间

                    #region 长沙处理曲线
                    if (m_mainform.sconnetname.Contains("智慧"))
                    {
                        //lzj20200928
                        {
                            var data = flag * ((m_SKGCSJmaxSpeed[imaxcount] - maxpowerspeed * 0.8f) / 10);
                            flag++;
                            m_SKGCSJmaxPower[imaxcount] = fFindMaxPower - data;
                            if (m_SKGCSJmaxPower[imaxcount] < fFindMaxPower * 0.78f)
                            {
                                m_SKGCSJmaxPower[imaxcount] = fFindMaxPower * 0.78f;
                            }
                            m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                        }
                        //lzj20200928
                    }
                    #endregion

                    imaxcount++;


                    //云景
                    //if (m_mainform.sconnetname.Contains("云景"))
                    {
                        //JsonData value = new LitJson.JsonData();
                        //value["InspectionNum"] = businessId;
                        //value["SceneCode"] = m_mainform.lineCode;
                        //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        //value["Second_NO"] = iobd + 1;
                        //value["Flow_RotateSpeed"] = ftrun;
                        //value["Flow_Speed"] = m_fspeed;
                        //value["Flow_LoadPower"] = fPower;
                        //value["Flow_Torque"] = fForce * flics;
                        //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                        //value["Flow_CO2"] = m_mainform.objbtg.m_fco2sk;
                        //value["Flow_NOX"] = m_mainform.objbtg.m_fnosk;
                        //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                        //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                        //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                        //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        //value["GKLX"] = "3";
                        //value["VelHP"] = m_fspeed * ((float)iedzs) / maxzhuansu;
                        //value["PowerCorrect"] = fpowerK;
                        //value["CorMaxPower"] = fPower * fpowerK;//问题
                        //value["ActMaxPower"] = fPower * fpowerK;//问题
                        //value["NFJZXS"] = 1;
                        //value["NFXS"] = 1;

                        //string svalue = value.ToJson();
                        //sendLUGGCSJ(businessId, svalue);

                        //model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
                        //objluggcsjzm.iobd = iobd + 1;
                        objluggcsjzm.ftrun = izhuansu;
                        objluggcsjzm.m_fspeed = m_fspeed;
                        objluggcsjzm.fPower = fPower;
                        objluggcsjzm.fnj = fForce * flics;
                        objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                        objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                        objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                        objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                        objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                        objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                        objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        objluggcsjzm.GKLX = 3;
                        objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                        objluggcsjzm.fpowerK = fpowerK;
                        objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                        objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                        objluggcsjzm.nlxzxs = 1;
                        objluggcsjzm.nlxs = 1;
                        //objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                        //sendLUGGCSJzm(businessId, objluggcsjzm);
                        //if (m_mainform.sfOBD)
                        //{
                        //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd);
                        //}
                        //igcsjcount++;
                    }



                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    //  WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;


                    dstart = DateTime.Now;






                }
            }

            for (int i80 = 0; i80 < 12; i80++)
            {
                dstart = DateTime.Now;
                while (true)
                {//变化速度不能超过2KM/H/S
                    Thread.Sleep(200);
                    //dcomfh = DateTime.Now;
                    //m_mainform.bcomsk = false;
                    //m_mainform.SendDeviceCmdSK();//  发送读取命令
                    //for (; ; )
                    //{
                    //    if (m_mainform.bcomsk || m_mainform.DateDiff(DateTime.Now, dcomfh) > 800)
                    //    {
                    //        break;
                    //    }
                    //}
                    //if (fcyzsqz.Contains("不透光"))
                    //{
                    //    ftrun = m_mainform.m_fzhuansuSK;
                    //}
                    //else
                    //{
                    //    ftrun = m_mainform.m_iTurn;
                    //}

                    //if (rbOBDZS.Checked)
                    //{
                    //    int ifdjzs = 0;
                    //    int.TryParse(m_mainform.OBD_fdjzs, out ifdjzs);
                    //    izhuansu = ifdjzs;
                    //}
                    //else
                    //{
                    //    izhuansu = m_mainform.objzsy.m_iGasturn;
                    //}
                    sxianshineirong = string.Format(@"检测80点保持住...");
                    szhuantai = "80点检测";
                    sshanghang = string.Format(@"检测80点");
                    sxiahang = string.Format(@"油门保持住...");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                    m_fgonglv = ((m_fspeed * fForce * flics) / 360);

                    //izhuansu = ftrun;
                    //xianshiyibiao();
                    xianshixinxi();

                    //xianshizhuansu();
                    //xianshipw();
                    fPower = ((m_fspeed * fForce * flics) / 360);
                    if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                    {

                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                        float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                        float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                        fForce = fzou + fyou + fhou;
                        if (fForce < 0)
                        {
                            fForce = 0;
                        }
                        if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                        {
                            float fgonglvdq = iedgl * 0.57f;
                            fForce = fgonglvdq * 360 / (m_fspeed * flics);
                        }

                        fPower = ((m_fspeed * fForce * flics) / 360);
                        m_SKGCSJ80K[i80count] = m_mainform.objbtg.m_fsk;//100点K值

                        if (m_mainform.jzjskz.Contains("否"))
                        {
                            if (m_SKGCSJ80K[i80count] < 0.01)
                            {
                                m_SKGCSJ80K[i80count] = ((float)m_mainform.getRandom(1, 3)) / 100f;
                            }
                            if (i80count > 0 && m_SKGCSJ80K[i80count] == m_SKGCSJ80K[i80count - 1])
                            {
                                m_SKGCSJ80K[i80count] = m_SKGCSJ80K[i80count] + 0.01f;
                            }
                        }
                        m_SKGCSJ80NO[i80count] = m_mainform.objbtg.m_fnosk;//
                        m_SKGCSJ80Speed[i80count] = m_fspeed;//100点速度
                        m_SKGCSJ80Power[i80count] = fPower;//100点功率
                        m_SKGCSJ80Turn[i80count] = izhuansu;//100点转速
                        m_SKGCSJ80Force[i80count] = fForce * flics;//100点加载力
                        m_SKGCSJ80youwen[i80count] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//100点油温    问题
                        //m_mainform.gethuanjing();//读取数据库环境参数 

                        m_SKGCSJ80wendu[i80count] = m_mainform.objbtg.m_fWenDu;//100点温度
                        m_SKGCSJ80shidu[i80count] = m_mainform.objbtg.m_fShiDu;//100点湿度
                        m_SKGCSJ80daqiya[i80count] = m_mainform.objbtg.m_fYaLi;//100点大气压
                        m_SKGCSJ80PowerK[i80count] = fpowerK;//100点功率修正系数
                        m_SKGCSJ80Time[i80count] = DateTime.Now.ToString();//100点采样时间

                        //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        iobd = imaxcount;// +i100count + i80count;
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                        igksj[2]++;
                        i80count++;


                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                        m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "4";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间

                        #region 长沙处理曲线
                        if (m_mainform.sconnetname.Contains("智慧"))
                        {
                            //lzj20200928
                            if (m_SKGCSJmaxPower[imaxcount] < fFindMaxPower * 0.8f * 0.98f || m_SKGCSJmaxPower[imaxcount] > fFindMaxPower * 0.8f * 1.1f)
                            {
                                m_SKGCSJmaxSpeed[imaxcount] = maxpowerspeed * 0.8f + (float)(objrd.Next(-10, 10) * 0.1);
                                m_SKGCSJmaxPower[imaxcount] = fFindMaxPower * 0.8f + (float)(objrd.Next(-10, 10) * 0.2);
                                m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                            }

                            if (m_SKGCSJmaxSpeed[imaxcount] < maxpowerspeed * 0.8f - 2 || m_SKGCSJmaxSpeed[imaxcount] > maxpowerspeed * 0.8f + 2)
                            {
                                m_SKGCSJmaxSpeed[imaxcount] = maxpowerspeed * 0.8f + (float)(objrd.Next(-10, 10) * 0.1);
                                m_SKGCSJmaxPower[imaxcount] = fFindMaxPower * 0.8f + (float)(objrd.Next(-10, 10) * 0.2);
                                m_SKGCSJmaxForce[imaxcount] = m_SKGCSJmaxPower[imaxcount] * 360 / m_SKGCSJmaxSpeed[imaxcount];
                            }
                            //lzj20200928

                        }
                        #endregion

                        imaxcount++;
                        VelMaxHP80End = imaxcount;

                        m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速80过程数据日志", hphm.Text),
                          string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                          m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));


                        zs80 = izhuansu;          //80%VelMaxHP 点发动机转速
                        zgxsd80 = m_fspeed;       //80%VelMaxHP 点转鼓线速度
                        lbgl80 = fPower;        //80%VelMaxHP 点轮边功率
                        //云景
                        //if (m_mainform.sconnetname.Contains("云景"))
                        {
                            //JsonData value = new LitJson.JsonData();
                            //value["InspectionNum"] = businessId;
                            //value["SceneCode"] = m_mainform.lineCode;
                            //value["ProcessTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            //value["Second_NO"] = iobd + 1;
                            //value["Flow_RotateSpeed"] = ftrun;
                            //value["Flow_Speed"] = m_fspeed;
                            //value["Flow_LoadPower"] = fPower;
                            //value["Flow_Torque"] = fForce * flics;
                            //value["Flow_K"] = m_mainform.objbtg.m_fsk;
                            //value["Flow_CO2"] = m_mainform.objbtg.m_fco2sk;
                            //value["Flow_NOX"] = m_mainform.objbtg.m_fnosk;
                            //value["EnvirTemperature"] = m_mainform.objbtg.m_fWenDu;
                            //value["EnvirAirPressure"] = m_mainform.objbtg.m_fYaLi;
                            //value["EnvirHumidity"] = m_mainform.objbtg.m_fShiDu;
                            //value["EngineOilTemperature"] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            //value["GKLX"] = "4";
                            //value["VelHP"] = m_fspeed * ((float)iedzs) / maxzhuansu;
                            //value["PowerCorrect"] = fpowerK;
                            //value["CorMaxPower"] = fPower * fpowerK;//问题
                            //value["ActMaxPower"] = fPower * fpowerK;//问题
                            //value["NFJZXS"] = 1;
                            //value["NFXS"] = 1;

                            //string svalue = value.ToJson();
                            //sendLUGGCSJ(businessId, svalue);

                            //model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
                            //objluggcsjzm.iobd = iobd + 1;
                            objluggcsjzm.ftrun = izhuansu;
                            objluggcsjzm.m_fspeed = m_fspeed;
                            objluggcsjzm.fPower = fPower;
                            objluggcsjzm.fnj = fForce * flics;
                            objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                            objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                            objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                            objluggcsjzm.dsxzxs = getKH();
                            objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                            objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                            objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                            objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                            objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            objluggcsjzm.GKLX = 4;
                            objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                            objluggcsjzm.fpowerK = fpowerK;
                            objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                            objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                            objluggcsjzm.nlxzxs = 1;
                            objluggcsjzm.nlxs = 1;
                            //objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                            //sendLUGGCSJzm(businessId, objluggcsjzm);
                            //if (m_mainform.sfOBD)
                            //{
                            //    m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd);
                            //}
                            //igcsjcount++;
                        }



                        inspectorNum = inspectorNum + 1;

                        sudu[ileng] = m_fspeed;
                        gl[ileng] = fPower;
                        f_sk[ileng] = m_mainform.objbtg.m_fsk;
                        //WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                        ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                        sgl[ileng] = string.Format(@"{0}", fPower);

                        WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                        ileng++;


                        break;
                    }
                }
            }

            bthread3 = true;
            m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq", "143");
            m_mainform.objbass.zhuapai(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh", "243");

            m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaoqian, "wqq");
            m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaohou, "wqh");
            m_mainform.objbass.luxiangjieshu(businessId, m_mainform.tongdaozhong, "wqqj");
            m_mainform.objbass.GetPic("43");//安车拍照发送命令
            m_mainform.objbass.GetPic("143");
            m_mainform.objbass.GetPic("243");

            sxianshineirong = string.Format(@"检测结束,请勿制动");
            szhuantai = "请勿制动";
            Thread.Sleep(1000);
            sshanghang = string.Format("请松油门");
            sxiahang = string.Format("请勿制动");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);


            xianshixinxi();


            //
            fsk = 0;
            fsno = 0;
            for (int j = 0; j < 12; j++)
            {
                fsk = fsk + m_SKGCSJ80K[j];
                fsno = fsno + m_SKGCSJ80NO[j];
            }
            m_sk80 = fsk / 12;// 读取到数据以后复制给变量
            m_sno80 = fsno / 12;
            m_jgsk80 = m_sk80;
            d80k = m_jgsk80;
            xianshi80k();

            while (true)
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;

                if (((m_fspeed * fForce * flics) / 360) > (iedgl * 0.57f))
                {
                    float fgonglvdq = iedgl * 0.57f;
                    fForce = fgonglvdq * 360 / (m_fspeed * flics);
                }
                fPower = ((m_fspeed * fForce * flics) / 360);
                xianshiyibiao();
                if (m_fspeed < 1)
                {
                    break;
                }
                Thread.Sleep(800);

                //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                {
                    sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                    xianshixinxi();
                    return false;
                }
                iobd = imaxcount;// +i100count + i80count;
                OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                OBD_fh[iobd] = m_mainform.OBD_fh;
                OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                OBD_cs[iobd] = m_mainform.OBD_cs;
                OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                OBD_jql[iobd] = m_mainform.OBD_jql;
                OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                OBD_scgl[iobd] = m_mainform.OBD_scgl;
                OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                OBD_hyl[iobd] = m_mainform.OBD_hyl;
                OBD_no[iobd] = m_mainform.OBD_no;
                OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                //igksj[2]++;
                //i80count++;

                double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                double dpow = Math.Pow(d1, 0.7);
                fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                double dpow11 = Math.Pow(d11, 0.7);
                double dpow12 = Math.Pow(d1, 1.5);
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }

                float yali = 0;
                if (m_mainform.objbtg.m_fYaLi > 0)
                {
                    yali = m_mainform.objbtg.m_fYaLi;
                }
                fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }

                m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                m_SKGCSJmaxNOxzxs[imaxcount] = (float)getKH();
                m_SKGCSJmaxNOxzh[imaxcount] = (float)(m_SKGCSJmaxNO[imaxcount] * getKH());
                m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                m_SKGCSJmaxjczt[imaxcount] = m_mainform.sconnetname.Contains("智慧") ? "5" : "0";
                //m_mainform.gethuanjing();//读取数据库环境参数 


                m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                imaxcount++;
            }

            m_mainform.DAC.PutVol(0);

            DateTime dtdszs = DateTime.Now;
            while (true)//
            {
                if (btgds1min)
                    break;
                if (DateTime.Now > dtdszs.AddSeconds(60))
                    break;
                sxianshineirong = string.Format("记录怠速转速{0}秒", Math.Round(60 - ((DateTime.Now - dtdszs).TotalSeconds)).ToString("0"));
                xianshixinxi();
                xianshizhuansu();
                Thread.Sleep(500);
            }
            Thread.Sleep(500);
            m_mainform.DAC.Lift(true);


            //上传结果
            timeEnd = DateTime.Now.ToLocalTime().ToString();
            if (m_mainform.TypeApprovalLimits == 0)
            {
                m_mainform.TypeApprovalLimits = 1.2f;

            }

             bgood = true;
             if (m_sk100 > m_mainform.TypeApprovalLimits || m_sk80 > m_mainform.TypeApprovalLimits || fFindMaxPower < ((double)iedgl) * 0.4 || m_sno80 > m_mainform.noxlimit)
            {
                bgood = false;
            }
            if (m_sno80 < 1)
            {
                m_sno80 = 35;
            }
            //if (maxpowertrun > 80)
            //{
            //    maxpowertrun = 67;
            //}
            //if (maxpowertrun < 1)
            //{
            //    maxpowertrun = 63;
            //}
            string sql = string.Format(@"update Detects_SJE set 
                                                ER1={0},
                                                ER2={1},
                                                ER3={2},
                                                SKTrun={3},
                                                SKPower={4},
                                                GasWenDu={5},
                                                GasShiDu={6},
                                                GasYaLi={7},
                                                Time_begin='{8}',
                                                Time_end='{9}',
                                                ERNO1={10},
                                                ERNO3={11},
                                                velmaxhp={12},
                                                WQPD='{13}'
                                                where DETECT_ID={14}  or ASM_JYLSH='{15}' ",
                                                 m_sk100,
                                                 m_sk90,
                                                 m_sk80,
                                                 maxpowertrun,
                                                 fFindMaxPower,
                                                 fwendu,
                                                 fshidu,
                                                 fdaqiya,
                                                 timeStart,
                                                 timeEnd,
                                                 m_sno100,
                                                 m_sno80,
                                                 maxpowerspeed,
                                                 bgood ? 1 : 2,
                                                 DETECT_ID,
                                                 businessId);
            m_mainform.objbass.objdb.InsertDB(sql);

            // 保存过程数据到本地数据库
            baocunGCSJ_LUG(businessId, m_mainform.testtimes);
            baocunGCSJ_OBD(businessId);
            // 保存过程数据到本地数据库
            //上传数据

            //录像结苏
            #region 安车
            //if (m_mainform.sconnetname.Contains("安车"))
            if (false)
            {
                //长沙安车平台
                //过程数据

                string cysx = "";
                string btgclz = "";
                string cs = "";
                string zs = "";
                string jzgl = "";
                string gxsxs = "";
                string zsgl = "";
                string yw = "";
                string glxzxs = "";
                string jsgl = "";
                string btgd = "";
                string dqyl = "";
                string xdsd = "";
                string hjwd = "";
                string sjxl = "";
                string nl = "";
                string jczt = "";
                string noxclz = "";
                string co2clz = "";
                string jcsj = "";
                string gksj = "";
                jcsj = (igksj[0] + igksj[1] + igksj[2]).ToString();
                gksj = string.Format("{0},{1},{2}", igksj[0], igksj[1], igksj[2]);
                for (int i = 0; i < imaxcount; i++)
                {
                    if (i == 0)
                    {

                        cysx = string.Format(@"{0}", i + 1);
                        btgclz = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        noxclz = string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                        cs = string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                        zs = string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                        jzgl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                        gxsxs = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        zsgl = string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                        yw = string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                        glxzxs = string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                        jsgl = string.Format(@"{0}", 0.5);
                        btgd = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        dqyl = string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                        xdsd = string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                        hjwd = string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                        sjxl = string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                        nl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                        jczt = string.Format(@"{0}", m_SKGCSJmaxjczt[i]);
                        co2clz = string.Format(@"{0}", m_SKGCSJmaxco2[i]);
                    }
                    else
                    {
                        cysx = cysx + "," + string.Format(@"{0}", i + 1);
                        btgclz = btgclz + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        noxclz = noxclz + "," + string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                        cs = cs + "," + string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                        zs = zs + "," + string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                        jzgl = jzgl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                        gxsxs = gxsxs + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        zsgl = zsgl + "," + string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                        yw = yw + "," + string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                        glxzxs = glxzxs + "," + string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                        jsgl = jsgl + "," + string.Format(@"{0}", 0.5);
                        btgd = btgd + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        dqyl = dqyl + "," + string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                        xdsd = xdsd + "," + string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                        hjwd = hjwd + "," + string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                        sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                        nl = nl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                        jczt = jczt + "," + string.Format(@"{0}", m_SKGCSJmaxjczt[i]);

                        co2clz = co2clz + "," + string.Format(@"{0}", m_SKGCSJmaxco2[i]);
                    }
                }

                string vehispara = "";
                string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
                stoubao = stoubao + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                               m_mainform.organ,
                                                              m_mainform.jkxlh,
                                                               "GC004");
                vehispara = stoubao + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <cyds>{2}</cyds>
                                <cysx>{3}</cysx>
                                <cs>{4}</cs>
			                    <zs>{5}</zs>
			                    <jzgl>{6}</jzgl>
			                    <gxsxs>{7}</gxsxs>
			                    <zsgl>{8}</zsgl>
			                    <yw>{9}</yw>
			                    <glxzxs>{10}</glxzxs>
			                    <jsgl>{11}</jsgl>
			                    <btgd>{12}</btgd>
			                    <dqyl>{13}</dqyl>
			                    <xdsd>{14}</xdsd>
			                    <hjwd>{15}</hjwd>
                                <sjxl>{16}</sjxl>
                                <nl>{17}</nl>
                                <jczt>{18}</jczt>
                                <btgclz>{19}</btgclz>
                                <noxclz>{20}</noxclz>
                                <co2clz>{21}</co2clz>
                                <jcsj>{22}</jcsj>
                                <gksj>{23}</gksj>
                                </vehispara>
                                </body>
                                </root>",
                                 businessId,
                                 m_mainform.testtimes,
                                 imaxcount,
                                 cysx,
                                 cs,
                                 zs,
                                 jzgl,
                                 gxsxs,
                                 zsgl,
                                 yw,
                                 glxzxs,
                                 jsgl,
                                 btgd,
                                 dqyl,
                                 xdsd,
                                 hjwd,
                                 sjxl,
                                 nl,
                                 jczt,
                                 btgclz,
                                 noxclz,
                                 co2clz,
                                 jcsj,
                                 gksj);



                obdsc();//发送OBD过程数据
                WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
                m_vesd.Url = m_mainform.surl;

                string sgc005 = m_mainform.decode(m_vesd.write(vehispara));
                if (!sgc005.ToUpper().Contains("<CODE>1</CODE>"))
                {
                    //m_mainform.baocunriji(string.Format("过程数据:{0}", m_mainform.decode(sgc005)));
                    //m_mainform.baocunrijiJGLUG(vehispara);
                    m_mainform.baocunRJ("LUG过程数据", vehispara); //
                    m_mainform.baocunRJ("LUG过程数据结果", m_mainform.decode(sgc005)); //
                    sxianshineirong = "上传过程数据失败 ";
                    xianshixinxi();
                }

                //过程数据

                //检测结果
                bgoodpf = true;
                if (m_sk100 > m_mainform.TypeApprovalLimits || m_sk80 > m_mainform.TypeApprovalLimits)
                {
                    bgoodpf = false;
                }

                string vehisparajg = "";
                string stoubaojg = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
                stoubaojg = stoubaojg + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                         m_mainform.organ,
                                                        m_mainform.jkxlh,
                                                         "JC004");
                vehisparajg = stoubaojg + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <wd>{2}</wd>
                                <dqy>{3}</dqy>
                                <xdsd>{4}</xdsd>
			                    <velmaxhp>{5}</velmaxhp>
			                    <rev100>{6}</rev100>
			                    <maxpower>{7}</maxpower>
			                    <maxpowerlimit>{8}</maxpowerlimit>
			                    <zdlbglzs>{9}</zdlbglzs>
			                    <zdlbgljudge>{10}</zdlbgljudge>
			                    <smokeklimit>{11}</smokeklimit>
			                    <ydjudge>{12}</ydjudge>
			                    <k100>{13}</k100>
			                    <k80>{14}</k80>
                                <nox>{15}</nox>
                                <noxlimit>{16}</noxlimit>
                                <raterevup>{17}</raterevup>
                                <raterevdown>{18}</raterevdown>
                                <result>{19}</result>
                                 </vehispara>
			                    </body>
                                </root>",
                                   businessId,
                                   m_mainform.testtimes,
                                    fwendu.ToString("0.00"),
                                    fdaqiya.ToString("0.00"),
                                    fshidu.ToString("0.00"),
                                   maxpowerspeed.ToString("0.00"),
                                   trunMax,
                                    fFindMaxPower.ToString("0.0"),
                                   0.4f * ((float)iedgl),
                                   trunMax,
                                   fFindMaxPower < (((float)iedgl) * 0.4f) ? 0 : 1,
                                   m_mainform.TypeApprovalLimits,
                                   bgoodpf ? 1 : 0,
                                   m_sk100.ToString("0.00"),
                                    m_sk80.ToString("0.00"),
                                    m_sno80.ToString("0.00"),
                                    m_mainform.noxlimit,
                                   iBiaoDingZhuanShu * 0.75f,
                                   iBiaoDingZhuanShu * 1.25f,
                                    bgood ? 1 : 0);
                string sjg005 = m_mainform.decode(m_vesd.write(vehisparajg));
                if (!sjg005.ToUpper().Contains("<CODE>1</CODE>"))
                {
                    m_mainform.baocunRJ("LUG结果数据", vehisparajg); //
                    m_mainform.baocunRJ("LUG结果数据结果", m_mainform.decode(sgc005)); //
                    sxianshineirong = "上传数据失败 ";
                    xianshixinxi();

                }


                m_mainform.sendjieshuAC(string.Format("{0}", bgood ? 1 : 0));//发送结束
            }
            #endregion
            else//云景的联网
            {
                bfh= senlwyj();
                m_mainform.objbass.XXTZ("05");//中科开始
            }
            if (bfh)
            {
                m_mainform.insertjcwc(businessId);
                m_mainform.objbass.stop(businessId, (bgood ? 1 : 0).ToString());
            }
            m_mainform.objbass.GetPIC("141");//加载减速100%拍照点前照
            m_mainform.objbass.GetPIC("241");//加载减速100%拍照点后照
            m_mainform.objbass.GetPIC("143");//加载减速80%拍照点前照
            m_mainform.objbass.GetPIC("243");//加载减速80%拍照点后照
            m_mainform.objbass.LuXiang("01", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
            m_mainform.objbass.LuXiang("02", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
            m_mainform.objbass.LuXiang("03", "http://193.112.138.21:8011/media/20181121/20181121001_1_h0.mp4");
            
            if (bgood)
            {
                m_mainform.flowwq.LedWrite("尾气排放检测", "合格", 1);
                sxianshineirong = string.Format(@"尾气排放合格");
                xianshixinxi();
            }
            else
            {
                m_mainform.flowwq.LedWrite("尾气排放检测", "不合格", 1);
                sxianshineirong = string.Format(@"尾气排放不合格");
                xianshixinxi();
            }
            Thread.Sleep(3000);
            m_mainform.flowwq.LedWrite("尾气排放检测", "", 1);


            thisclose();

            return true;
        }
        public bool senlwyj()
        {
            model.LUG.LUGsj objsj = new model.LUG.LUGsj();
            objsj.fwendu = fwendu;
            objsj.fdaqiya = fdaqiya;
            objsj.fshidu = fshidu;
            objsj.m_sk100 = m_sk100;
            objsj.m_sk80 = m_sk80;
            objsj.m_sno80 = (int)m_sno80;
            objsj.fFindMaxPower = (float)fFindMaxPower;
            objsj.maxpowerspeed = (float)maxpowerspeed;
            objsj.bgood = bgood;

            objsj.fiedgl =iedgl;

            objsj.nox100 = nox100; //100%VelMaxHP 点NOx 值
            objsj.zs100 = zs100; //100%VelMaxHP 点发动机转速
            objsj.zgxsd100 = zgxsd100; //100%VelMaxHP 点转鼓线速度
            objsj.lbgl100 = lbgl100; //100%VelMaxHP 点轮边功率
            objsj.zs80 = zs80; //80%VelMaxHP 点发动机转速
            objsj.zgxsd80 = zgxsd80; //80%VelMaxHP 点转鼓线速度
            objsj.lbgl80 = lbgl80; //80%VelMaxHP 点轮边功率
            objsj.sczdlbgl = sczdlbgl; //扫描阶段实测最大轮边功率
            objsj.xzzdlbgl = xzzdlbgl; //扫描阶段修正最大轮边功率
            objsj.zdlbglxzxs = zdlbglxzxs; //扫描阶段轮边功率修正系数
            objsj.zdlbglsd = zdlbglsd; //最大轮边功率对应的速度
            objsj.zdlbglfdjzs = zdlbglfdjzs; //最大轮边功率对应的发动机转速
            objsj.fdjdszs = fdjdszs; //发动机怠速转速
            objsj.zdlbglsjxsd = zdlbglsjxsd; //实际VelMaxHp（最大轮边功率时滚筒线速度）
            objsj.raterevup= iedzs * 0.75f;
            objsj.raterevdown = iedzs * 1.25f;
           
                                  


            model.LUG.LUGgcsj objgcsj = new model.LUG.LUGgcsj();

            objgcsj.imaxcount = imaxcount; //InspectTime	int	总检测时间（多少秒）
            //objgcsj.imaxcount = imaxcount;//WorkTime	int	工况时间（多少秒）

            objgcsj.PowerScanStart = PowerScanStart;//               Integer	功率扫描阶段起始时间
            objgcsj.PowerScanEnd = PowerScanEnd;//                Integer	功率扫描阶段结束时间
            objgcsj.VelMaxHP100Start = VelMaxHP100Start;//	                 Integer	100%VelMaxHP阶段起始时间
            objgcsj.VelMaxHP100End = VelMaxHP100End;//               Integer	100%VelMaxHP阶段结束时间
            objgcsj.VelMaxHP80Start = VelMaxHP80Start; //                Integer	80%VelMaxHP阶段起始时间
            objgcsj.VelMaxHP80End = VelMaxHP80End;//                Integer	80%VelMaxHP阶段结束时间


            objgcsj.m_SKGCSJmaxSpeed = m_SKGCSJmaxSpeed; // 车速 单位，km/h
            objgcsj.m_SKGCSJmaxForce = m_SKGCSJmaxForce; // 测功机扭矩（Nm）
            objgcsj.m_SKGCSJmaxK = m_SKGCSJmaxK; // 光吸收系数（单位：m-1）
            objgcsj.m_SKGCSJmaxNO = m_SKGCSJmaxNO; // NOx浓度（单位：10-6）
            objgcsj.m_SKGCSJmaxPower = m_SKGCSJmaxPower; // 总加载功率 单位，kW
            objgcsj.m_SKGCSJmaxTurn = m_SKGCSJmaxTurn; // 发动机转速 单位，r/min
            objgcsj.m_SKGCSJmaxyouwen = m_SKGCSJmaxyouwen; //     油温（单位: ℃）
            objgcsj.m_SKGCSJmaxN = m_SKGCSJmaxN; // 不透光度（单位：%）
            objgcsj.m_SKGCSJmaxco2 = m_SKGCSJmaxco2; // CO2浓度（单位：% vol）
            objgcsj.m_SKGCSJmaxwendu = m_SKGCSJmaxwendu; //     环境温度 单位，℃
            objgcsj.m_SKGCSJmaxshidu = m_SKGCSJmaxshidu; //     环境相对湿度， 单位，%
            objgcsj.m_SKGCSJmaxdaqiya = m_SKGCSJmaxdaqiya; //     环境大气压 单位，kPa
            objgcsj.m_SKGCSJmaxPowerK = m_SKGCSJmaxPowerK; //     功率修正系数
            objgcsj.m_SKGCSJmaxTime = m_SKGCSJmaxTime; //     当前过程数据时刻(yyyy-MM-dd HH:mm:ss)
            objgcsj.m_SKGCSJmaxjczt = m_SKGCSJmaxjczt;//状态
            objgcsj.jcsj = (igksj[0] + igksj[1] + igksj[2]).ToString();//新增
            objgcsj.gcsj = string.Format("{0},{1},{2}", igksj[0], igksj[1], igksj[2]);//新增


            //OBD
            model.LUG.LUGobdgcsj objobdgcsj = new model.LUG.LUGobdgcsj();
            objobdgcsj.ObdThrottle = OBD_jqmkd;
            objobdgcsj.ObdSpeed = OBD_cs;
            objobdgcsj.ObdPower = OBD_scgl;
            objobdgcsj.ObdRPM = OBD_fdjzs;
            objobdgcsj.ObdAirInput = OBD_jql;
            objobdgcsj.ObdBoostPressure = OBD_zyyl;
            objobdgcsj.ObdFuelConsumption = OBD_hyl;
            objobdgcsj.ObdNOx = OBD_no;
            objobdgcsj.ObdSCR = OBD_nsbsl;
            objobdgcsj.ObdEGT = OBD_pqwd;
            objobdgcsj.ObdDPF = OBD_klbjqyc;
            objobdgcsj.ObdEGR = OBD_egrkd;
            objobdgcsj.ObdEFI = OBD_rypsyl;
            objobdgcsj.ObdAirPressure = OBD_jqyl;//新增
            objobdgcsj.ObdExcessAirFactor = OBD_glkqxs;//新增
            objobdgcsj.ObdPreOxygen = OBD_qycgqxh;//新增
            objobdgcsj.ObdCLV = OBD_fh;//新增
            objobdgcsj.Obdsjxl = OBD_sjxl;//新增
            objobdgcsj.Obdymkd = OBD_ymkd;//新增
            string message = m_mainform.objbass.sjuploadLUG(businessId, objsj, objgcsj, objobdgcsj);
            if (!message.Contains("1"))
            {
                sxianshineirong = message;
                xianshixinxi();
                Thread.Sleep(3000);
                return false;
            }
            return true;
        }
        private void TESTLUG_Resize(object sender, EventArgs e)
        {
            float newx = (this.Width) / x;
            float newy = (this.Height) / y;
            setControls(newx, newy, this);
        }

       

       

        private void zhongzhijance_Click(object sender, EventArgs e)
        {
            LUG_Stop = true;
            for (; ; )
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                xianshiyibiao();
                if (m_fspeed < 1)
                {
                    break;
                }
            }
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(500);
            m_mainform.DAC.Lift(true);
            //m_mainform.insertjcwc(businessId); 中止不发结束识别位
            this.Close();
        }

        private void TESTLUG_FormClosed(object sender, FormClosedEventArgs e)
        {
            //m_mainform.SendDeviceCmdSKTZ();
            m_mainform.objbtg.SendDeviceCmd(2);
            if (LUG_Start)
            {
                t1.Abort();
                t1.DisableComObjectEagerCleanup();

                t2.Abort();
                t2.DisableComObjectEagerCleanup();


                t3.Abort();
                t3.DisableComObjectEagerCleanup();

            }

        }

        public void WriteGraph(ZedGraphControl zgc)
        {
            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[0]), 45.0f);
            // 设置图表的颜色填充，如果设置为FillType.None,则填充色和背景色相同
            myPane.Chart.Fill.Type = FillType.None;
           
            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("过程曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "过程数据";

           

            zgc.AxisChange();
            zgc.Invalidate();
        }

        private void aGauge13_ValueInRangeChanged(object sender, AGaugeApp.AGauge.ValueInRangeChangedEventArgs e)
        {

        }



        private void skinBut_ksjc_Click(object sender, EventArgs e)
        {

            m_mainform.objbtg.SendDeviceCmd(1);
            Thread.Sleep(1000);
            m_mainform.DAC.PutVol(0);

            skinBut_ksjc.Enabled = false;
            t1 = new Thread(new ThreadStart(Thread1));
            t1.Priority = ThreadPriority.BelowNormal;
            t1.Start();

            Thread.Sleep(1000);
            t2 = new Thread(new ThreadStart(Thread2));
            t2.Priority = ThreadPriority.BelowNormal;
            t2.Start();


            t3 = new Thread(new ThreadStart(Thread3));
            t3.Priority = ThreadPriority.BelowNormal;
            t3.Start();

        }

        private void skinBut_zjjc_Click(object sender, EventArgs e)
        {
            m_mainform.objbtg.bbtgco2 = false;
            m_mainform.DAC.PutVol(0);
            bthread3 = true;
            //m_mainform.SendDeviceCmdSKTZ();
            m_mainform.objbtg.SendDeviceCmd(2);
            Thread.Sleep(500);
            m_mainform.objbtg.SendDeviceCmd(4);
            LUG_Stop = true;
            for (; ; )
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                xianshiyibiao();
                if (m_fspeed < 1)
                {
                    break;
                }
            }
            m_mainform.DAC.PutVol(0);
            Thread.Sleep(500);
            m_mainform.DAC.Lift(true);
            try
            {
                t3.Abort();
                t3.DisableComObjectEagerCleanup();
            }
            catch (Exception ) { }
            this.Close();
        }

        private void skinBut_jssq_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(true);
        }

        private void skinBut_jsxj_Click(object sender, EventArgs e)
        {
            m_mainform.DAC.Lift(false);
        }

        private void skinBut_sz_Click(object sender, EventArgs e)
        {
            LUGpeizhi obj = new LUGpeizhi();
            obj.ShowDialog();
        }
        public void WriteGraphGCQX(ZedGraphControl zgc, float[] speed, float[] pw, float[] sk, int icount)
        {
            //判断每条曲线的最大值
            double ispmax = 0;
            for (int i = 0; i < icount; i++)
            {

                if (ispmax < (double)speed[i])
                {
                    ispmax = (double)speed[i];
                }

            }
            ispmax = ispmax * 1.1;

            double ipwmax = 0;
            for (int i = 0; i < icount; i++)
            {

                if (ipwmax < (double)(pw[i]))
                {
                    ipwmax = (double)(pw[i]);
                }

            }
            ipwmax = ipwmax * 1.1;

            double iskmax = 0;
            for (int i = 0; i < icount; i++)
            {

                if (iskmax < (double)(sk[i]))
                {
                    iskmax = (double)(sk[i]);
                }

            }
            iskmax = iskmax * 1.1;



            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[0]), 45.0f);
            // 设置图表的颜色填充，如果设置为FillType.None,则填充色和背景色相同
            myPane.Chart.Fill.Type = FillType.None;

            // Set the titles and axis labels
            myPane.Title.Text = string.Format(@"加载减速过程曲线");
            myPane.XAxis.Title.Text = "时间, s";
            myPane.YAxis.Title.Text = "速度, km/h";
            myPane.Y2Axis.Title.Text = "功率, kw";



           

            // Make up some data points based on the Sine function
            PointPairList vList = new PointPairList();
            PointPairList pList = new PointPairList();
            PointPairList kList = new PointPairList();
           

           

            // Fabricate some data values




            for (int i = 0; i < icount; i++)
            {
                double time = (double)i;

                vList.Add(time, (double)speed[i]);
                pList.Add(time, (double)pw[i]);
                kList.Add(time, (double)sk[i]);

            }


            // Generate a red curve with diamond symbols, and "Velocity" in the legend
            LineItem myCurve = myPane.AddCurve("速度",
               vList, Color.Red, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);




           



           



            // Generate a blue curve with circle symbols, and "Acceleration" in the legend
            myCurve = myPane.AddCurve("功率",
               pList, Color.Blue, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the Y2 axis
            myCurve.IsY2Axis = true;

            // Generate a green curve with square symbols, and "Distance" in the legend
            myCurve = myPane.AddCurve("排放",
               kList, Color.Lime, SymbolType.None);
            myCurve.Line.Width = 1.7F;
            // Fill the symbols with white
            myCurve.Symbol.Fill = new Fill(Color.White);
            // Associate this curve with the second Y axis
            myCurve.YAxisIndex = 1;



            // Show the x axis grid
            myPane.XAxis.MajorGrid.IsVisible = true;

            // Make the Y axis scale red
            myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
            myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane.YAxis.MajorTic.IsOpposite = false;
            myPane.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane.YAxis.Scale.Align = AlignP.Inside;
            myPane.YAxis.Scale.Max = ispmax;//最大值

            // Enable the Y2 axis display
            myPane.Y2Axis.IsVisible = true;
            // Make the Y2 axis scale blue
            myPane.Y2Axis.Scale.FontSpec.FontColor = Color.Blue;
            myPane.Y2Axis.Title.FontSpec.FontColor = Color.Blue;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            myPane.Y2Axis.MajorTic.IsOpposite = false;
            myPane.Y2Axis.MinorTic.IsOpposite = false;
            // Display the Y2 axis grid lines
            myPane.Y2Axis.MajorGrid.IsVisible = true;
            // Align the Y2 axis labels so they are flush to the axis
            myPane.Y2Axis.Scale.Align = AlignP.Inside;
            myPane.Y2Axis.Scale.Min = 1.5;
            myPane.Y2Axis.Scale.Max = ipwmax;

            // Create a second Y Axis, green
            YAxis yAxis3 = new YAxis("排放, 10-6");
            myPane.YAxisList.Add(yAxis3);
            yAxis3.Scale.FontSpec.FontColor = Color.Lime;
            yAxis3.Title.FontSpec.FontColor = Color.Lime;
            yAxis3.Color = Color.Green;
            // turn off the opposite tics so the Y2 tics don't show up on the Y axis
            yAxis3.MajorTic.IsInside = false;
            yAxis3.MinorTic.IsInside = false;
            yAxis3.MajorTic.IsOpposite = false;
            yAxis3.MinorTic.IsOpposite = false;
            yAxis3.Scale.Max = iskmax;
            // Align the Y2 axis labels so they are flush to the axis
            //   yAxis3.Scale.Align = AlignP.Inside;



            // Fill the axis background with a gradient
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

            zgc.AxisChange();
            zgc.Invalidate();
        }

        public void WriteGraphEX(ZedGraphControl zgc, string[] izdz, string[] izdy, double imax, int icount)
        {
            imax = 90;
            GraphPane myPane = zgc.GraphPane;
            myPane.Fill = new Fill(Color.White, Color.Aqua, 45.0f);
            myPane.Legend.Fill = new Fill(Color.Gainsboro);
            myPane.Chart.Fill = new Fill(Color.Gainsboro);

            myPane.CurveList.Clear();

            myPane.Title.Text = string.Format("曲线");

            myPane.XAxis.Title.Text = "时间(s)";
            myPane.YAxis.Title.Text = "速度(km/h)";

            myPane.YAxis.MajorGrid.IsVisible = false;
            myPane.YAxis.MinorTic.Size = 0f;

            myPane.YAxis.Scale.Min = 0;
            myPane.YAxis.Scale.Max = imax + 0;


            myPane.YAxis.Scale.MajorStep = 1;



            zgc.IsShowPointValues = true;//数据节点
            string ss0 = string.Format("速度");
            string ss1 = string.Format("功率");

            PointPairList list0 = new PointPairList();
            PointPairList list1 = new PointPairList();


            LineItem myCurve0 = myPane.AddCurve(ss0, list0, Color.Blue,
                                    SymbolType.None);
            LineItem myCurve1 = myPane.AddCurve(ss1, list1, Color.Red,
                                    SymbolType.None);
            myCurve0.Line.Width = 1.7F;
            myCurve1.Line.Width = 1.7F;

            for (int i = 0; i < icount; i++)
            {
                double dx = 0;
                double dy = 0;
                double.TryParse(izdz[i], out dx);
                double.TryParse(izdy[i], out dy);
                list0.Add(i, dx);
                list1.Add(i, dy);
            }
            zgc.AxisChange();
            zgc.Invalidate();
        }


        public bool zhongzhijiance()//CO2 或者温度超出要求终止检测
        {
            //return false;

            if (m_mainform.objbtg.m_fco2sk < 2)
            {
                return true;
            }
            if (m_mainform.objbtg.m_fWenDu > 40)
            {
                return true;
            }
            return false;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (m_mainform.DateDiff(DateTime.Now, dtl) > itlsj * 1000)
            {
                xinxixianshi.Text = string.Format("调零完毕请插入采样探头");
                threadzj = new Thread(zijian);
                threadzj.Start();
                timer1.Enabled = false;
            }
        }

        Thread threadzj;
        bool bzijian = true;
        public void zijian()
        {
            for (int i = 0; i < 2; i++)
            {
                while (true)
                {
                    m_mainform.objbtg.SendDeviceCmd(3);
                    if (!bzijian)
                    {
                        sxianshineirong = string.Format(@"自检结束");
                        string sshanghangx = string.Format("自检结束");
                        string sxiahangx = string.Format("");
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshixinxi();//
                        MethodInvoker ln = new MethodInvoker(setkaishi);
                        this.BeginInvoke(ln);
                        return;
                    }
                    Thread.Sleep(100);
                    if (i == 0)
                    {
                        sxianshineirong = string.Format(@"当前{0}%检测0%", m_mainform.objbtg.m_fnssk);
                        string sshanghangx = string.Format("检测0%");
                        string sxiahangx = string.Format("当前{0}%", m_mainform.objbtg.m_fnssk);
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshixinxi();//
                        if (m_mainform.objbtg.m_fnssk < 2)
                        {
                            Thread.Sleep(500);

                            sxianshineirong = string.Format(@"0%不透光合格");
                            sshanghangx = string.Format("0%不透光合格");
                            sxiahangx = string.Format("");
                            m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                            xianshixinxi();//
                            Thread.Sleep(2000);
                            break;
                        }
                    }
                    else
                    {
                        sxianshineirong = string.Format(@"当前{0}%检测100%", m_mainform.objbtg.m_fnssk);
                        string sshanghangx = string.Format("检测100%");
                        string sxiahangx = string.Format("当前{0}%", m_mainform.objbtg.m_fnssk);
                        m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                        xianshixinxi();
                        if (m_mainform.objbtg.m_fnssk > 98)
                        {
                            Thread.Sleep(500);
                            sxianshineirong = string.Format(@"100%不透光合格");
                            sshanghangx = string.Format("100%不透光合格");
                            sxiahangx = string.Format("");
                            m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                            xianshixinxi();//
                            Thread.Sleep(2000);
                            break;
                        }
                    }
                }
            }
            {
                sxianshineirong = string.Format(@"自检结束");
                string sshanghangx = string.Format("自检结束");
                string sxiahangx = string.Format("");
                m_mainform.flowwq.LedWrite(sshanghangx, sxiahangx, 1);
                xianshixinxi();//
            }
            MethodInvoker lnex = new MethodInvoker(setkaishi);
            this.BeginInvoke(lnex);
        }
        public void setkaishi()
        {
            skinBut_ksjc.Enabled = true;
        }
        //记录自由加速过程数据
        public void baocunGCSJ_LUG(string sjylsh, string stime)
        {
            string cysx = "";
            string btgclz = "";
            string cs = "";
            string zs = "";
            string jzgl = "";
            string gxsxs = "";
            string zsgl = "";
            string yw = "";
            string glxzxs = "";
            string jsgl = "";
            string btgd = "";
            string dqyl = "";
            string xdsd = "";
            string hjwd = "";
            string sjxl = "";
            string nl = "";
            string jczt = "";
            string noxclz = "";
            string co2clz = "";
            string scyxzxs = "";
            string noxxzh = "";

            for (int i = 0; i < imaxcount; i++)
            {
                if (i == 0)
                {
                    cysx = string.Format(@"{0}", i + 1);
                    btgclz = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    noxclz = string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                    cs = string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                    zs = string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                    jzgl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                    gxsxs = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    zsgl = string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                    yw = string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                    glxzxs = string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                    jsgl = string.Format(@"{0}", 0.5);
                    btgd = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    dqyl = string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                    xdsd = string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                    hjwd = string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                    sjxl = string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                    nl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                    jczt = string.Format(@"{0}", m_SKGCSJmaxjczt[i]);

                    co2clz = string.Format(@"{0}", m_SKGCSJmaxco2[i]);
                    scyxzxs = string.Format(@"{0}", m_SKGCSJmaxNOxzxs[i]);
                    noxxzh = string.Format(@"{0}", m_SKGCSJmaxNOxzh[i]);
                }
                else
                {
                    cysx = cysx + "," + string.Format(@"{0}", i + 1);
                    btgclz = btgclz + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    noxclz = noxclz + "," + string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                    cs = cs + "," + string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                    zs = zs + "," + string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                    jzgl = jzgl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                    gxsxs = gxsxs + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    zsgl = zsgl + "," + string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                    yw = yw + "," + string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                    glxzxs = glxzxs + "," + string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                    jsgl = jsgl + "," + string.Format(@"{0}", 0.5);
                    btgd = btgd + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                    dqyl = dqyl + "," + string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                    xdsd = xdsd + "," + string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                    hjwd = hjwd + "," + string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                    sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                    nl = nl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                    jczt = jczt + "," + string.Format(@"{0}", m_SKGCSJmaxjczt[i]);

                    co2clz = co2clz + "," + string.Format(@"{0}", m_SKGCSJmaxco2[i]);

                    scyxzxs = scyxzxs + "," + string.Format(@"{0}", m_SKGCSJmaxNOxzxs[i]);
                    noxxzh = noxxzh + "," + string.Format(@"{0}", m_SKGCSJmaxNOxzh[i]);

                }
            }


            ///保存数据库中
            string sql;
            sql = string.Format(@"Select *  from GCSJ_LUG where jylsh='{0}' and  time='{1}'", sjylsh, stime);
            DataTable dt = m_mainform.objbass.objdb.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update GCSJ_LUG  set GCSJ_LUG_ydzds='{0}'
                                                          ,GCSJ_LUG_fdjdszs='{1}'
                                                          ,GCSJ_LUG_yw='{2}'
                                                          ,GCSJ_LUG_hjwd='{3}'
                                                          ,GCSJ_LUG_dqyl='{4}'
                                                          ,GCSJ_LUG_xdsd='{5}'
                                                          ,GCSJ_LUG_sjxl='{6}'
                                                          ,GCSJ_LUG_cs='{7}'
                                                          ,GCSJ_LUG_jzgl='{8}'
                                                          ,GCSJ_LUG_zsgl='{9}'
                                                          ,GCSJ_LUG_glxzxs='{10}'
                                                          ,GCSJ_LUG_nj='{11}'
                                                          ,GCSJ_LUG_noxclz='{12}'
                                                          ,GCSJ_LUG_co2clz='{13}'
                                                          ,GCSJ_LUG_noxz='{16}'
                                                          ,jczt='{17}'
                                                          ,GCSJ_LUG_noxzh='{18}'
                                                        where jylsh='{14}' and  time='{15}' ",
                                                        btgclz,
                                                        zs,
                                                        yw,
                                                        hjwd,
                                                        dqyl,
                                                        xdsd,
                                                        sjxl,
                                                        cs,
                                                        jzgl,
                                                        zsgl,
                                                        glxzxs,
                                                        nl,
                                                        noxclz,
                                                        co2clz,
                                                        sjylsh,
                                                        stime,
                                                        scyxzxs,
                                                        jczt,
                                                        noxxzh);


            }
            else
            {

                sql = string.Format(@"insert into GCSJ_LUG (
                                               jylsh
                                                ,time
                                                ,GCSJ_LUG_ydzds
                                                ,GCSJ_LUG_fdjdszs
                                                ,GCSJ_LUG_yw
                                                ,GCSJ_LUG_hjwd
                                                ,GCSJ_LUG_dqyl
                                                ,GCSJ_LUG_xdsd
                                                ,GCSJ_LUG_sjxl
                                                ,GCSJ_LUG_cs
                                                ,GCSJ_LUG_jzgl
                                                ,GCSJ_LUG_zsgl
                                                ,GCSJ_LUG_glxzxs
                                                ,GCSJ_LUG_nj
                                                ,GCSJ_LUG_noxclz
                                                ,GCSJ_LUG_co2clz
                                                ,GCSJ_LUG_noxz
                                                ,jczt
                                                ,GCSJ_LUG_noxzh) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                 '{9}',
                                                 '{10}',
                                                 '{11}',
                                                 '{12}',
                                                 '{13}',
                                                 '{14}',
                                                 '{15}',
                                                 '{16}',
                                                 '{17}',
                                                 '{18}')",
                                                sjylsh,
                                                stime,
                                                btgclz,
                                                zs,
                                                yw,
                                                hjwd,
                                                dqyl,
                                                xdsd,
                                                sjxl,
                                                cs,
                                                jzgl,
                                                zsgl,
                                                glxzxs,
                                                nl,
                                                noxclz,
                                                co2clz,
                                                scyxzxs,
                                                jczt,
                                                noxxzh);
            }
            m_mainform.objbass.objdb.InsertDB(sql);
            //


        }

        public void baocunGCSJ_OBD(string sjylsh)
        {
            string sobdgcsj_jqmkd = "";
            string sobdgcsj_fh = "";
            string sobdgcsj_qycgqxh = "";
            string sobdgcsj_glkqxs = "";
            string sobdgcsj_ymkd = "";
            string sobdgcsj_cs = "";
            string sobdgcsj_fdjzs = "";
            string sobdgcsj_jql = "";
            string sobdgcsj_jqyl = "";
            string sobdgcsj_scgl = "";
            string sobdgcsj_zyyl = "";
            string sobdgcsj_hyl = "";
            string sobdgcsj_no = "";
            string sobdgcsj_nsbsl = "";
            string sobdgcsj_pqwd = "";
            string sobdgcsj_klbjqyc = "";
            string sobdgcsj_egrkd = "";
            string sobdgcsj_rypsyl = "";
            string sobdgcsj_sj = "";
            for (int iz = 0; iz < objasmobds.ObdThrottle.Length; iz++)
            {
                if (!string.IsNullOrWhiteSpace(objasmobds.obdjcsj[iz]))
                {
                    sobdgcsj_jqmkd = sobdgcsj_jqmkd + "" + ",";
                    sobdgcsj_fh = sobdgcsj_fh + "" + ",";
                    sobdgcsj_qycgqxh = sobdgcsj_qycgqxh + "" + ",";
                    sobdgcsj_glkqxs = sobdgcsj_glkqxs + "" + ",";
                    sobdgcsj_ymkd = sobdgcsj_ymkd + objasmobds.ObdThrottle[iz] + ",";
                    sobdgcsj_cs = sobdgcsj_cs + objasmobds.ObdSpeed[iz] + ",";
                    sobdgcsj_fdjzs = sobdgcsj_fdjzs + objasmobds.ObdRPM[iz] + ",";
                    sobdgcsj_jql = sobdgcsj_jql + objasmobds.ObdAirInput[iz] + ",";
                    sobdgcsj_jqyl = sobdgcsj_jqyl + "" + ",";
                    sobdgcsj_scgl = sobdgcsj_scgl + objasmobds.ObdPower[iz] + ",";
                    sobdgcsj_zyyl = sobdgcsj_zyyl + objasmobds.ObdBoostPressure[iz] + ",";
                    sobdgcsj_hyl = sobdgcsj_hyl + objasmobds.ObdFuelConsumption[iz] + ",";
                    sobdgcsj_no = sobdgcsj_no + objasmobds.ObdNOx[iz] + ",";
                    sobdgcsj_nsbsl = sobdgcsj_nsbsl + objasmobds.ObdSCR[iz] + ",";
                    sobdgcsj_pqwd = sobdgcsj_pqwd + objasmobds.ObdEGT[iz] + ",";
                    sobdgcsj_klbjqyc = sobdgcsj_klbjqyc + objasmobds.ObdDPF[iz] + ",";
                    sobdgcsj_egrkd = sobdgcsj_egrkd + objasmobds.ObdEGR[iz] + ",";
                    sobdgcsj_rypsyl = sobdgcsj_rypsyl + objasmobds.ObdEFI[iz] + ",";
                    sobdgcsj_sj = sobdgcsj_sj + objasmobds.obdjcsj[iz] + ",";
                }
            }

            sobdgcsj_jqmkd = sobdgcsj_jqmkd.TrimEnd(',');
            sobdgcsj_fh = sobdgcsj_fh.TrimEnd(',');
            sobdgcsj_qycgqxh = sobdgcsj_qycgqxh.TrimEnd(',');
            sobdgcsj_glkqxs = sobdgcsj_glkqxs.TrimEnd(',');
            sobdgcsj_ymkd = sobdgcsj_ymkd.TrimEnd(',');
            sobdgcsj_cs = sobdgcsj_cs.TrimEnd(',');
            sobdgcsj_fdjzs = sobdgcsj_fdjzs.TrimEnd(',');
            sobdgcsj_jql = sobdgcsj_jql.TrimEnd(',');
            sobdgcsj_jqyl = sobdgcsj_jqyl.TrimEnd(',');
            sobdgcsj_scgl = sobdgcsj_scgl.TrimEnd(',');
            sobdgcsj_zyyl = sobdgcsj_zyyl.TrimEnd(',');
            sobdgcsj_hyl = sobdgcsj_hyl.TrimEnd(',');
            sobdgcsj_no = sobdgcsj_no.TrimEnd(',');
            sobdgcsj_nsbsl = sobdgcsj_nsbsl.TrimEnd(',');
            sobdgcsj_pqwd = sobdgcsj_pqwd.TrimEnd(',');
            sobdgcsj_klbjqyc = sobdgcsj_klbjqyc.TrimEnd(',');
            sobdgcsj_egrkd = sobdgcsj_egrkd.TrimEnd(',');
            sobdgcsj_rypsyl = sobdgcsj_rypsyl.TrimEnd(',');
            sobdgcsj_sj = sobdgcsj_sj.TrimEnd(',');
            string ssql = string.Format("select * from OBD_ZGCSJ where jylsh='{0}'", sjylsh);
            DataTable dt = m_mainform.objbass.objdb.GetTable(ssql);
            if (dt.Rows.Count > 0)
            {
                ssql = string.Format(@"update OBD_ZGCSJ  set 
sobdgcsj_jqmkd='{0}'
,sobdgcsj_fh='{1}'
,sobdgcsj_qycgqxh='{2}'
,sobdgcsj_glkqxs='{3}'
,sobdgcsj_ymkd='{4}'
,sobdgcsj_cs='{5}'
,sobdgcsj_fdjzs='{6}'
,sobdgcsj_jql='{7}'
,sobdgcsj_jqyl='{8}'
,sobdgcsj_scgl='{9}'
,sobdgcsj_zyyl='{10}'
,sobdgcsj_hyl='{11}'
,sobdgcsj_no='{12}'
,sobdgcsj_nsbsl='{13}'
,sobdgcsj_pqwd='{14}'
,sobdgcsj_klbjqyc='{15}'
,sobdgcsj_egrkd='{16}'
,sobdgcsj_rypsyl='{17}'
,sobdgcsj_sj='{18}'
                                                        where jylsh='{19}'",
sobdgcsj_jqmkd
 , sobdgcsj_fh
 , sobdgcsj_qycgqxh
 , sobdgcsj_glkqxs
 , sobdgcsj_ymkd
 , sobdgcsj_cs
 , sobdgcsj_fdjzs
 , sobdgcsj_jql
 , sobdgcsj_jqyl
 , sobdgcsj_scgl
 , sobdgcsj_zyyl
 , sobdgcsj_hyl
 , sobdgcsj_no
 , sobdgcsj_nsbsl
 , sobdgcsj_pqwd
 , sobdgcsj_klbjqyc
 , sobdgcsj_egrkd
 , sobdgcsj_rypsyl
 , sobdgcsj_sj
 , sjylsh);


            }
            else
            {

                ssql = string.Format(@"insert into OBD_ZGCSJ (
                                               jylsh
                                               ,sobdgcsj_jqmkd 
 ,sobdgcsj_fh 
 ,sobdgcsj_qycgqxh 
 ,sobdgcsj_glkqxs 
 ,sobdgcsj_ymkd 
 ,sobdgcsj_cs 
 ,sobdgcsj_fdjzs 
 ,sobdgcsj_jql 
 ,sobdgcsj_jqyl 
 ,sobdgcsj_scgl 
 ,sobdgcsj_zyyl 
 ,sobdgcsj_hyl 
 ,sobdgcsj_no 
 ,sobdgcsj_nsbsl 
 ,sobdgcsj_pqwd 
 ,sobdgcsj_klbjqyc 
 ,sobdgcsj_egrkd 
 ,sobdgcsj_rypsyl 
 ,sobdgcsj_sj ) values (
                                                '{0}',
                                                '{1}',
                                                '{2}',
                                                '{3}',
                                                '{4}',
                                                '{5}',
                                                '{6}',
                                                '{7}',
                                                '{8}',
                                                '{9}',
                                                '{10}',
                                                '{11}',
                                                '{12}',
                                                '{13}',
                                                '{14}',
                                                '{15}',
                                                '{16}',
                                                '{17}',
                                                '{18}',
                                                '{19}')",
sjylsh
, sobdgcsj_jqmkd
, sobdgcsj_fh
, sobdgcsj_qycgqxh
, sobdgcsj_glkqxs
, sobdgcsj_ymkd
, sobdgcsj_cs
, sobdgcsj_fdjzs
, sobdgcsj_jql
, sobdgcsj_jqyl
, sobdgcsj_scgl
, sobdgcsj_zyyl
, sobdgcsj_hyl
, sobdgcsj_no
, sobdgcsj_nsbsl
, sobdgcsj_pqwd
, sobdgcsj_klbjqyc
, sobdgcsj_egrkd
, sobdgcsj_rypsyl
, sobdgcsj_sj);
            }
            m_mainform.objbass.objdb.InsertDB(ssql);
        }
        public void obdsc()
        {
            string cyds = "";
            string cysx = "";
            string sjxl = "";
            string jqmkd = "";
            string fh = "";
            string qycgqxh = "";
            string glkqxs = "";
            string ymkd = "";
            string cs = "";
            string fdjzs = "";
            string jql = "";
            string jqyl = "";
            string scgl = "";
            string zyyl = "";
            string hyl = "";
            string no = "";
            string nsbsl = "";
            string pqwd = "";
            string klbjqyc = "";
            string egrkd = "";
            string rypsyr = "";
            string jczt = "";

            for (int i = 0; i <= iobd; i++)
            {
                cyds = iobd.ToString();
                cysx = (i + 1).ToString();
                sjxl = sjxl + OBD_sjxl + ",";
                jqmkd = jqmkd + OBD_jqmkd[i] + ",";
                fh = fh + OBD_fh[i] + ",";
                qycgqxh = qycgqxh + OBD_qycgqxh[i] + ",";
                glkqxs = glkqxs + OBD_glkqxs[i] + ",";
                ymkd = ymkd + OBD_ymkd[i] + ",";
                cs = cs + OBD_cs[i] + ",";
                fdjzs = fdjzs + OBD_fdjzs[i] + ",";
                jql = jql + OBD_jql[i] + ",";
                jqyl = jqyl + OBD_jqyl[i] + ",";
                scgl = scgl + OBD_scgl[i] + ",";
                zyyl = zyyl + OBD_zyyl[i] + ",";
                hyl = hyl + OBD_hyl[i] + ",";
                no = no + OBD_no[i] + ",";
                nsbsl = nsbsl + OBD_nsbsl[i] + ",";
                pqwd = pqwd + OBD_pqwd[i] + ",";
                klbjqyc = klbjqyc + OBD_klbjqyc[i] + ",";
                egrkd = egrkd + OBD_egrkd[i] + ",";
                rypsyr = rypsyr + OBD_rypsyl[i] + ",";
                //jczt      = jczt    +       [i]+",";
            }
            cyds = cyds.Trim(',');
            cysx = cysx.Trim(',');
            sjxl = sjxl.Trim(',');
            jqmkd = jqmkd.Trim(',');
            fh = fh.Trim(',');
            qycgqxh = qycgqxh.Trim(',');
            glkqxs = glkqxs.Trim(',');
            ymkd = ymkd.Trim(',');
            cs = cs.Trim(',');
            fdjzs = fdjzs.Trim(',');
            jql = jql.Trim(',');
            jqyl = jqyl.Trim(',');
            scgl = scgl.Trim(',');
            zyyl = zyyl.Trim(',');
            hyl = hyl.Trim(',');
            no = no.Trim(',');
            nsbsl = nsbsl.Trim(',');
            pqwd = pqwd.Trim(',');
            klbjqyc = klbjqyc.Trim(',');
            egrkd = egrkd.Trim(',');
            rypsyr = rypsyr.Trim(',');
            jczt = jczt.Trim(',');
            string vehispara = "";
            string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            stoubao = stoubao + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                           m_mainform.organ,
                                                          m_mainform.jkxlh,
                                                           "GC011");
            vehispara = stoubao + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <cyds>{2}</cyds>
                                <cysx>{3}</cysx>
                                <sjxl>{4}</sjxl>
                                <jqmkd>{5}</jqmkd>
                                <fh>{6}</fh>
                                <qycgqxh>{7}</qycgqxh>
                                <glkqxs>{8}</glkqxs>
                                <ymkd>{9}</ymkd>
                                <cs>{10}</cs>
                                <fdjzs>{11}</fdjzs>
                                <jql>{12}</jql>
                                <jqyl>{13}</jqyl>
                                <scgl>{14}</scgl>
                                <zyyl>{15}</zyyl>
                                <hyl>{16}</hyl>
                                <no>{17}</no>
                                <nsbsl>{18}</nsbsl>
                                <pqwd>{19}</pqwd>
                                <klbjqyc>{20}</klbjqyc>
                                <egrkd>{21}</egrkd>
                                <rypsyr>{22}</rypsyr>
                                <jczt>{23}</jczt>
                                 </vehispara>
			                    </body>
                                </root>",
                                   businessId,
                                   m_mainform.testtimes,
                                  cyds,
            cysx,
            sjxl,
            jqmkd,
            fh,
            qycgqxh,
            glkqxs,
            ymkd,
            cs,
            fdjzs,
            jql,
            jqyl,
            scgl,
            zyyl,
            hyl,
            no,
            nsbsl,
            pqwd,
            klbjqyc,
            egrkd,
            rypsyr,
            jczt);


            //过程数据
            WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
            m_vesd.Url = m_mainform.surl;
            string sgc005 = m_vesd.write(vehispara);// m_mainform.decode();
            if (!sgc005.ToUpper().Contains("<CODE>1</CODE>"))
            {

                m_mainform.baocunRJ("OBD过程数据", vehispara); //
                m_mainform.baocunRJ("OBD过程数据结果", m_mainform.decode(sgc005)); //
                sxianshineirong = "上传OBD过程数据失败 ";
                xianshixinxi();
                return;
            }

        }

        double d100k = 0;
        double d80k = 0;
        private void xianshi100k()
        {
            if (this.zhuansu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi100k);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txt100k.Text = d100k.ToString("0.00");
            }
        }

        private void xianshi80k()
        {
            if (this.zhuansu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshi80k);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.txt80k.Text = d80k.ToString("0.00");
            }
        }




        public void sendLUGGCSJ(string businessId, string svalue)
        {

            m_mainform.objbass.senddate("HJ15", svalue);
        }
        public void sendLUGGCSJzm(string businessId, model.LUG.LUGgcsjZM objgcsj)
        {

            m_mainform.objbass.zmgcsjlug(businessId, objgcsj);
        }

        public void sendLUGJG(string businessId)
        {
            JsonData value = new LitJson.JsonData();
            value["InspectionNum"] = businessId;
            value["StationCode"] = m_mainform.stationCode;
            value["SceneCode"] = m_mainform.lineCode;
            value["VLPN"] = m_mainform.VLPN;
            value["VLPNColor"] = m_mainform.VLPNColor;
            value["VIN"] = m_mainform.VIN;
            value["InspectionOperator"] = m_mainform.InspectionOperator;
            value["InspectionDriver"] = m_mainform.InspectionDriver;
            value["ICheck"] = m_mainform.InspectionOperator;
            value["CheckTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            value["Temperature"] = fwendu;
            value["Pressure"] = fdaqiya;
            value["Humidity"] = fshidu;
            value["IUTID"] = string.Format("{0}{1}{2}", m_mainform.stationCode, m_mainform.lineCode, m_mainform.IUTID);
            value["IUIDATE"] = DateTime.Now.ToString("yyyy-MM-dd");
            value["DetectStartTime"] = timeStart;
            value["DetectEndTime"] = timeEnd;
            value["VDCT"] = bgood ? "1" : "0";
            value["LPSItem"] = 1;
            value["ER100"] = m_sk100;
            value["ER80"] = m_sk80;
            value["NOX80"] = m_sno80;
            value["MWP"] = fFindMaxPower;
            value["EL"] = m_mainform.TypeApprovalLimits;
            value["ED"] = bgoodpf ? "1" : "0";
            value["NOXEL"] = m_mainform.noxlimit;
            value["NOXED"] = m_sno80 > m_mainform.noxlimit ? "1" : "0";
            value["VelMaxHP"] = maxpowerspeed;



            string svalue = value.ToJson();
            m_mainform.objbass.senddate("HJ16", svalue);
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        public bool bthread3 = false;
        public bool bthread_time = false;


        model.LUG.LUGgcsjZM objluggcsjzm = new model.LUG.LUGgcsjZM();
        public int igcsjcount = 1;
        public int igcsjcount_obd = 1;
        public bool bsenddate = false;
        public DateTime dtgcsj;
        public DateTime sendDate;
        public DateTime sendDate2;

        model.LUG.LUGobdgcsj objasmobds = new model.LUG.LUGobdgcsj();
        public void Thread3()
        {
            dtgcsj = DateTime.Now;
            int icountobdds = 0;
            //if (!m_mainform.sconnetname.Contains("安车") && !m_mainform.sconnetname.Contains("智慧"))
            {
                while (true)
                {
                    Thread.Sleep(300);
                    //
                    if (bsenddate)
                    {
                        if (m_mainform.DateDiff(DateTime.Now, sendDate) > 900 && !bthread_time)
                        {
                            bthread_time = true;
                            sendDate = DateTime.Now;
                            objluggcsjzm.ProcessTime = dtgcsj.AddSeconds(igcsjcount).ToString("yyyy-MM-dd HH:mm:ss");
                            objluggcsjzm.iobd = igcsjcount;
                            if (m_mainform.objbass.zmgcsjlug(businessId, objluggcsjzm).Contains("1"))
                            {
                                igcsjcount++;
                            }
                            if (m_mainform.sfOBD)
                            {
                                // if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount_obd).ToString("yyyy-MM-dd HH:mm:ss"), objluggcsjzm.iobd).Contains("1"))
                                if (m_mainform.objbass.sendOBDGCSJ(businessId, dtgcsj.AddSeconds(igcsjcount_obd).ToString("yyyy-MM-dd HH:mm:ss"), igcsjcount_obd).Contains("1"))
                                {
                                    igcsjcount_obd++;
                                }
                            }

                            bthread_time = false;
                        }
                    }

                    //fwj20200814
                    DateTime dtimeobddq = DateTime.Now;
                    if (icountobdds > 0 && dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss") == objasmobds.obdjcsj[icountobdds - 1])
                    {
                        icountobdds--;
                    }
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                    }
                    objasmobds.ObdThrottle[icountobdds] = m_mainform.OBD_ymkd.Length < 1 ? "0" : m_mainform.OBD_ymkd;
                    objasmobds.ObdSpeed[icountobdds] = m_mainform.OBD_cs.Length < 1 ? "0" : m_mainform.OBD_cs;
                    objasmobds.ObdPower[icountobdds] = m_mainform.OBD_scgl.Length < 1 ? "0" : m_mainform.OBD_scgl;
                    objasmobds.ObdRPM[icountobdds] = m_mainform.OBD_fdjzs.Length < 1 ? "0" : m_mainform.OBD_fdjzs;
                    objasmobds.ObdAirInput[icountobdds] = m_mainform.OBD_jql.Length < 1 ? "0" : m_mainform.OBD_jql;
                    objasmobds.ObdBoostPressure[icountobdds] = m_mainform.OBD_zyyl.Length < 1 ? "0" : m_mainform.OBD_zyyl;
                    objasmobds.ObdFuelConsumption[icountobdds] = m_mainform.OBD_hyl.Length < 1 ? "0" : m_mainform.OBD_hyl;
                    objasmobds.ObdNOx[icountobdds] = m_mainform.OBD_no.Length < 1 ? "0" : m_mainform.OBD_no;
                    objasmobds.ObdSCR[icountobdds] = m_mainform.OBD_nsbsl.Length < 1 ? "0" : m_mainform.OBD_nsbsl;
                    objasmobds.ObdEGT[icountobdds] = m_mainform.OBD_pqwd.Length < 1 ? "0" : m_mainform.OBD_pqwd;
                    objasmobds.ObdDPF[icountobdds] = m_mainform.OBD_klbjqyc.Length < 1 ? "0" : m_mainform.OBD_klbjqyc;
                    objasmobds.ObdEGR[icountobdds] = m_mainform.OBD_egrkd.Length < 1 ? "0" : m_mainform.OBD_egrkd;
                    objasmobds.ObdEFI[icountobdds] = m_mainform.OBD_rypsyl.Length < 1 ? "0" : m_mainform.OBD_rypsyl;
                    objasmobds.obdjcsj[icountobdds] = dtimeobddq.ToString("yyyy-MM-dd HH:mm:ss");
                    icountobdds++;
                    //
                    if (bthread3)
                    {
                        break;
                    }
                    if (m_mainform.DateDiff(DateTime.Now, sendDate2) > 1500 && m_mainform.sconnetname.Contains("安车") && byw)
                    {
                        sendDate2 = DateTime.Now;
                        //if (m_mainform.sconnetname.Contains("安车") && byw)
                        {

                            fywrg = float.Parse((fywrg + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));

                            if (fywrg > 110)
                            {
                                fywrg = float.Parse((110 + m_mainform.getRandom(1, 5) * 0.05f).ToString("0.00"));
                            }
                        }
                    }
                    Thread.Sleep(500);
                }
                //lzj
            }
            
        }

        private void TESTLUG_FormClosing(object sender, FormClosingEventArgs e)
        {

            m_mainform.DAC.PutVol(0);
        }

        float fywrg = 0;
        bool byw = false;
        private void 油温人工确认ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = string.Format(@"
CREATE TABLE [dbo].[ywrgqr](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[jylsh] [varchar](50) NULL,
	[hphm] [varchar](50) NULL,
	[yuanyin] [varchar](500) NULL,
	[czy] [varchar](50) NULL,
	[yw] [real] NULL,
	[lrtime] [datetime] NULL
) ON [PRIMARY]");
            try
            {
                m_mainform.objbass.objdb.InsertDB(sql);
            }
            catch (Exception ) { }

            尾气流程仪表.youwenrengong f = new 尾气流程仪表.youwenrengong();
            f.slsh = businessId;
            f.shphm = hphm.Text;
            f.scaozuoyuan = m_mainform.InspectionOperator;
            if (f.ShowDialog() == DialogResult.OK)
            {
                byw = true;
                fywrg = f.fyw;
                sql = string.Format("insert into ywrgqr (jylsh,hphm,yuanyin,czy,yw,lrtime) values ('{0}','{1}','{2}','{3}',{4},'{5}')",
                    f.slsh, f.shphm, f.syuanyin, f.scaozuoyuan, f.fyw, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                m_mainform.objbass.objdb.InsertDB(sql);
            }
        }

        private void form_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                oBD上传ToolStripMenuItem.Visible = true;
                跳过自检ToolStripMenuItem.Visible = true;
                跳过怠速ToolStripMenuItem.Visible = true;
                        toolStripMenuItem2.Visible = true;
            }

        }

        private void form_KeyUp(object sender, KeyEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
            跳过怠速ToolStripMenuItem.Visible = false;
            toolStripMenuItem2.Visible = false;
        }

        private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
        {
            oBD上传ToolStripMenuItem.Visible = false;
            跳过自检ToolStripMenuItem.Visible = false;
            跳过怠速ToolStripMenuItem.Visible = false;
            toolStripMenuItem2.Visible = false;
        }
        bool bobdhg = false;
        private void oBD上传ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bobdhg = true;
        }

        private void TESTLUG_Load(object sender, EventArgs e)
        {

            bobdhg = false;
        }

        private void 跳过自检ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bzijian = false;
        }
        bool btgds1min = false;
        private void 跳过怠速ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btgds1min = true;
        }


        public bool TestLUGDOWN(double dTimeOut, float fedgl, float fSpeedEx, float iBiaoDingZhuanShu)
        {
            //录像开始

            PowerScanStart = imaxcount + 1;
            imaxcount = 0;//扫描最大功率第几秒。
            timeStart = DateTime.Now.ToLocalTime().ToString();
            int inspectorNum = 1;
            m_sk100 = 0;
         
            m_sk80 = 0;
            m_sno100 = 0;
            m_sno80 = 0;

            //float fStep = 1;
            float powerMax = 0;
            double outputMax = 0;
            float speedMax = 0;
            float trunMax = 0;
            double fpowerK;

            float maxpowerK = 0;
            double maxpoweroutput = 0;
            float maxpowertrun = 0;
            float maxpower = 0;
            maxpowerspeed = 0;
            float fspeed100 = 0;
            float fspeed80 = 0;
            double dshuchu100 = 0;
            float maxturn = 0;

            m_mainform.DAC.tiaoling(1);

            DateTime dcomfh = DateTime.Now;

            sxianshineirong = "环境采集中。。。";
            szhuantai = "环境采集";

            string sshanghang = sxianshineirong;
            string sxiahang = "";
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            xianshixinxi();
            float maxzhuansu = 1000;

            fwendu = m_mainform.objbtg.m_fWenDu;
            fshidu = m_mainform.objbtg.m_fShiDu;
            fdaqiya = m_mainform.objbtg.m_fYaLi;
          
            sxianshineirong = "环境采集完毕";
            szhuantai = "环境采集";
            xianshixinxi();

            DateTime dateyw = DateTime.Now;
            Thread.Sleep(1500);
            //油温检测开始
            while (true)
            {

                Thread.Sleep(300);
                sxianshineirong = string.Format("当前油温:{0}度不符合测试要求", (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK));
                xianshixinxi();
                if ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) > 80)
                {
                    break;
                }
            }
            while (true)
            {
                sxianshineirong = string.Format("{0}。请插入转速", izhuansu);
                xianshixinxi();
                Thread.Sleep(500);
                if (izhuansu > 500)
                {
                    break;
                }
            }
            DateTime dateyw2 = DateTime.Now;
            m_mainform.objbtg.SendDeviceCmd(3);

            model.尾气自检.检测前自检.zijianlug objzj = new model.尾气自检.检测前自检.zijianlug();

            objzj.dtBeginTime = DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtEndTime = DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
            objzj.nCheckResult = "1";
            objzj.fEnvTemperature = m_mainform.objbtg.m_fWenDu.ToString();
            objzj.fEnvHumidity = m_mainform.objbtg.m_fShiDu.ToString();
            objzj.fEnvPressure = m_mainform.objbtg.m_fYaLi.ToString();
            objzj.nEnvTemperatureOK = "1";
            objzj.nEnvHumidityOK = "1";
            objzj.nEnvPressureOK = "1";
            objzj.dtOilTmpCheckBeginTime = dateyw.ToString("yyyy-MM-dd HH:mm:ss");
            objzj.dtOilTmpCheckEndTime = dateyw2.ToString("yyyy-MM-dd HH:mm:ss");
            objzj.fOilTemperature = ((byw ? fywrg : m_mainform.objbtg.m_fyouwenSK) < 80) ? m_mainform.getRandom(81, 89).ToString() : (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK).ToString();
            objzj.nOilTemperatureResult = "1";
            objzj.fKCheckP0Point = "0";
            objzj.fKCheckP100Point = (99f + ((float)m_mainform.getRandom(1, 9) * 0.1f)).ToString();
            objzj.nKCheckP0PointOK = "1";
            objzj.nKCheckP100PointOK = "1";

            m_mainform.objbass.jianceqianzj(businessId, objzj);

            if (m_mainform.objbass.start(businessId, "", "", "", bobdhg) == "0")
                return false;
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaoqian, "wqq");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaohou, "wqh");//智慧
            m_mainform.objbass.luxiangkaishi(businessId, shphm, shpzl, m_mainform.tongdaozhong, "wqqj");//智慧

            DateTime dstart = DateTime.Now;

          
            szhuantai = "";
            xianshixinxi();


            sshanghang = string.Format("空档油门踩到底 记录最大转速");
            sxiahang = string.Format("保持3-5秒");
            xianshixinxi();
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

           

            //获取最大车速、转速
            sxianshineirong = string.Format(@"直接档油门踩到底保持住");
            sshanghang = string.Format("选择合适档");
            sxiahang = string.Format("油门踩到底");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            szhuantai = "";
            xianshixinxi();
            float fZhiJieDanMaxSpeed = 0;
            float fPower = 0;
            var OBD_FDJZS = 0;
            int iKongDanMaxTrun = 1;
          
            dstart = DateTime.Now;
            while (true)//
            {
                if (LUG_Stop)
                {
                    m_mainform.flowwq.LedWrite("终止检测", "请减速", 1);
                    sxianshineirong = string.Format(@"终止检测 请减速");
                    xianshixinxi();
                    return false;
                }
                if (m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                {
                    int.TryParse(m_mainform.OBD_fdjzs, out OBD_FDJZS);
                }
                if (OBD_FDJZS > 0)//取OBD转速
                {
                    if (iKongDanMaxTrun < OBD_FDJZS)
                    {
                        iKongDanMaxTrun = OBD_FDJZS;
                    }
                }
                else
                {
                    if (maxzhuansu < izhuansu)
                    {
                        maxzhuansu = izhuansu;
                    }
                }

                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                sshanghang = string.Format("加速到70km/h左右");
                sxiahang = string.Format("速度:{0:N1}", m_fspeed);
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                szhuantai = "";
                xianshixinxi();
                if (fZhiJieDanMaxSpeed > 90)
                {
                    fZhiJieDanMaxSpeed = 0;
                    sxianshineirong = string.Format(@"速度大于90km/h请降低一个档位....");
                    sshanghang = string.Format("速度大于90");
                    sxiahang = string.Format("请降低一个档位");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    xianshixinxi();
                    dstart = DateTime.Now;
                }
                if (fZhiJieDanMaxSpeed < m_fspeed)
                {
                    fZhiJieDanMaxSpeed = m_fspeed;
                }
                if ((DateTime.Now - dstart).TotalMilliseconds > 10 * 1000)//10秒还采集不到最大速度
                {
                    break;
                }
                if (m_fspeed < 30)
                {
                    dstart = DateTime.Now;
                }
               
                if (m_fspeed > 40)
                {

                    {
                        float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                        float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                        float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                        fForce = fzou + fyou + fhou;
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);



                        iobd = imaxcount;// +i100count + i80count;
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }

                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "0";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                        imaxcount++;
                    }
                }
            }
            //采集完最大速度/转速
            var maxHP_65 = 0.0f;
            var maxHP_90 = 0.0f;
            var maxHP_40 = 0.0f;
            maxHP_65 =(float) (0.65 * fedgl);
            maxHP_90 = (float)(0.90 * fedgl);
            maxHP_40 = (float)(0.40 * fedgl);

            var VelMaxHP_G = 0.0f;
            var MaxHP_G = 0.0f;
            var ai_G = 0.0f;
            var t_G = 0.0f;

            VelMaxHP_G = (float)((fZhiJieDanMaxSpeed * iBiaoDingZhuanShu) / maxzhuansu);
            MaxHP_G = maxHP_65;
            ai_G = 0.2f;
            t_G = 50f;

            m_mainform.objbass.uploadimage(businessId);

            //计算对应的最大轮边转速  
            sxianshineirong = string.Format(@"开始扫描最大功率....");
            sshanghang = string.Format("保持油门");
            sxiahang = string.Format("开始扫描最大功率");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
            szhuantai = "";
            xianshixinxi();

            fFindMaxPower = 0;//记录最大功率
            float fPrePower = 0;//上一次的功率

            double fOutPut = 800;
            dstart = DateTime.Now;
            DateTime LUG_Start_Time = DateTime.Now;
            dcomfh = DateTime.Now;


            DateTime dtgcsj = DateTime.Now;
            bsenddate = true;
            sendDate = DateTime.Now;
            bthread3 = false;
            bthread_time = false;

            //增加一个初始功率后开始计算部进

            setForc(60);//大概10kw左右
            while (true)
            {
                if (LUG_Stop)
                {
                    m_mainform.flowwq.LedWrite("终止检测", "请减速", 1);
                    sxianshineirong = string.Format(@"终止检测 请减速");
                    xianshixinxi();
                    return false;
                }
                szhuantai = "";
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);
                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }
                m_fgonglv = (m_fspeed * fForce * flics) / 360;
                m_mainform.baocunrijiLI(string.Format("当前：{0}  零位：{1}", fForce, m_fgonglv));
                xianshixinxi();
                Thread.Sleep(100);
                if ((m_mainform.DateDiff(DateTime.Now, dstart) > 3 * 1000))
                {
                    break;
                }
            }
            var af_g = 0.0f;//扭力加载预估值
            af_g = (float)(3600 * (maxzhuansu * MaxHP_G - iBiaoDingZhuanShu * m_fgonglv) / (t_G * fZhiJieDanMaxSpeed * iBiaoDingZhuanShu));

            var count = 1;//加载次数
            var fore100 = 0.0f;
            var fore80 = 0.0f;
            while (true)
            {
                if (LUG_Stop)
                {
                    m_mainform.flowwq.LedWrite("终止检测", "请减速", 1);
                    sxianshineirong = string.Format(@"终止检测 请减速");
                    xianshixinxi();
                    return false;
                }
                szhuantai = "";
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);
                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }
                m_fgonglv = (m_fspeed * fForce * flics) / 360;
                m_mainform.baocunrijiLI(string.Format("当前：{0}  零位：{1}", fForce, m_fgonglv));
                xianshixinxi();
                Thread.Sleep(100);
                fPower = (m_fspeed * fForce * flics) / 360;
                fPrePower = fPower;
                if (fFindMaxPower < fPower)
                {//记录最大功率，和此时的输出
                    fFindMaxPower = fPower;//记录
                    powerMax = fFindMaxPower;
                    outputMax = fOutPut;
                    trunMax = izhuansu;
                    maxpowerK = m_mainform.objbtg.m_fsk;
                    maxpoweroutput = fOutPut * fsccs;
                    maxpowertrun = izhuansu;
                    maxpower = fPower;
                    maxpowerspeed = m_fspeed;// *((float)iedzs) / maxzhuansu;
                    speedMax = m_fspeed;
                    maxturn = izhuansu;
                    //中科宇图字段
                    zdlbglfdjzs = maxzhuansu;   //最大轮边功率对应的发动机转速
                    zdlbglxzxs = ((float)iedzs) / maxzhuansu;   //扫描阶段轮边功率修正系数
                    sczdlbgl = fFindMaxPower;      //扫描阶段实测最大轮边功率
                    xzzdlbgl = fFindMaxPower * ((float)iedzs) / maxzhuansu;      //扫描阶段修正最大轮边功率
                    zdlbglsd = m_fspeed;      //最大轮边功率对应的速度
                    zdlbglsjxsd = m_fspeed;    //实际VelMaxHp（最大轮边功率时滚筒线速度）

                    fspeed100 = speedMax;
                    fspeed80 = (float)(0.8 * speedMax);
                    fore100 = 60 + count * af_g;//记录100点时候的输出
                  

                }
              
               
                if (m_fspeed < fspeed80 - 0.2)
                {
                    fore80 = 60 + count * af_g;//记录80点时候的输出
                }
                #region 发送过程数据

                double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                double dpow = Math.Pow(d1, 0.7);
                float yali = 0;
                if (m_mainform.objbtg.m_fYaLi > 0)
                {
                    yali = m_mainform.objbtg.m_fYaLi;
                }
                fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                double d11 = (99 / yali);
                double dpow11 = Math.Pow(d11, 0.7);
                double dpow12 = Math.Pow(d1, 1.5);
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                m_SKGCSJmaxjczt[imaxcount] = "0";
              
                m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;
                m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;
                m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;
                m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                iobd = imaxcount;

                if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                {
                    sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                    xianshixinxi();
                    return false;
                }
                OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                OBD_fh[iobd] = m_mainform.OBD_fh;
                OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                OBD_cs[iobd] = m_mainform.OBD_cs;
                OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                OBD_jql[iobd] = m_mainform.OBD_jql;
                OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                OBD_scgl[iobd] = m_mainform.OBD_scgl;
                OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                OBD_hyl[iobd] = m_mainform.OBD_hyl;
                OBD_no[iobd] = m_mainform.OBD_no;
                OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                //云景
      
                objluggcsjzm.ftrun = izhuansu;
                objluggcsjzm.m_fspeed = m_fspeed;
                objluggcsjzm.fPower = fPower;
                objluggcsjzm.fnj = fForce * flics;
                objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                objluggcsjzm.dsxzxs = getKH();
                objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                objluggcsjzm.GKLX = 0;
                objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                objluggcsjzm.fpowerK = double.IsInfinity(fpowerK) ? 1 : fpowerK;
                objluggcsjzm.fpowerXZMAX = double.IsInfinity(fPower * fpowerK) ? 1 : fPower * fpowerK;//问题
                objluggcsjzm.fpowerSCMAX = double.IsInfinity(fPower * fpowerK) ? 1 : fPower * fpowerK;//问题
                objluggcsjzm.nlxzxs = 1;
                objluggcsjzm.nlxs = 1;
                imaxcount++;

                PowerScanEnd = imaxcount;
                countmax = imaxcount;
                #endregion

                #region  //达到一秒后记录数据到数组中
                if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                {
                    setForc(60 + count * af_g);//每年增量加载
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }
                    dstart = DateTime.Now;
                    if (fshidu < 1)
                    {
                        fwendu = m_mainform.objbtg.m_fWenDu;
                        fshidu = m_mainform.objbtg.m_fShiDu;
                        fdaqiya = m_mainform.objbtg.m_fYaLi;
                    }
                    inspectorNum = inspectorNum + 1;
                    m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速扫描功率过程数据日志", hphm.Text),
                   string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                   m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));

                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;

                }
                #endregion

                igksj[0]++;
                if (m_fspeed > 20 && m_fspeed < fspeed80 - 0.2)
                {//这里退出扫描最大功率
                    break;
                }
                else if ((m_mainform.DateDiff(DateTime.Now, dstart) > 60 * 1000))
                {
                    fore80 = 60 + count * af_g;//记录80点时候的输出
                    break;
                }
            }
            ///////////////////////100点

            maxpowertrun = maxturn;
            ///////////////////////1000点
            m_mainform.DAC.PutVol(0);//电流复位
            int i100count = 0;

            VelMaxHP100Start = imaxcount + 1;
            sxianshineirong = string.Format(@"检测100%MaxHp排放速度{0:N1}", maxpowerspeed);
            xianshixinxi();
            sshanghang = string.Format(@"检测100%");
            sxiahang = string.Format(@"MaxHp速度{0:N1}", maxpowerspeed);
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            int iwendingdianshu = 0;
            bool bkzd = false;
            DateTime dstart100 = DateTime.Now;
            while (true)//调整加载，然后稳定后测量开始。。。
            {

                Thread.Sleep(100);
                if (iwendingdianshu > 2)
                {
                    break;
                }

                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                sxianshineirong = string.Format(@"100点速度{0};当前{1}", maxpowerspeed.ToString("0.00"), m_fspeed.ToString("0.00"));
                szhuantai = "100点检测";

                sshanghang = string.Format(@"100点速度{0}", maxpowerspeed.ToString("0.00"));
                sxiahang = string.Format(@"当前{0}", m_fspeed.ToString("0.00"));
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                m_fgonglv = (m_fspeed * fForce * flics) / 360;

                double dsc100 = dshuchu100;
                if (bkzd)
                {
                    setForc(fore100);//每年增量加载
                    if (m_mainform.DateDiff(DateTime.Now, dstart100) > 1000 * 3)
                    {
                        break;
                    }
                }


                if (m_fspeed > -2 && !bkzd)
                {

                    setForc(fore100/2);
                    Thread.Sleep(300);
                    bkzd = true;
                    dstart100 = DateTime.Now;

                }

                xianshixinxi();
                m_mainform.bcomsk = false;
                dcomfh = DateTime.Now;
                fPower = (m_fspeed * fForce * flics) / 360;
                if (m_mainform.DateDiff(DateTime.Now, dstart) > 1000)
                {
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }

                    dstart = DateTime.Now;
                    if (m_fspeed > fspeed100 - 1 && m_fspeed < fspeed100 + 1)
                    {
                        iwendingdianshu++;
                    }
                    else
                    {
                        iwendingdianshu = 0;
                    }
                    double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                    double dpow = Math.Pow(d1, 0.7);
                    fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                    double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                    double dpow11 = Math.Pow(d11, 0.7);
                    double dpow12 = Math.Pow(d1, 1.5);
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    
                    iobd = imaxcount;// +i100count;
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        return false;
                    }
                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                    igksj[1]++;
                    //i100count++;


                    float yali = 0;
                    if (m_mainform.objbtg.m_fYaLi > 0)
                    {
                        yali = m_mainform.objbtg.m_fYaLi;
                    }
                    fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                    m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                    m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                    m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                    m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                    m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                    m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                    m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                    m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                    m_SKGCSJmaxjczt[imaxcount] = "1";
                   
                    m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;
                    m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;
                    m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;

                    m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                    m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                    imaxcount++;

                    m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速100过程数据日志", hphm.Text),
                      string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                      m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));

                    //云景
                  
                    {
                       
                        objluggcsjzm.ftrun = izhuansu;
                        objluggcsjzm.m_fspeed = m_fspeed;
                        objluggcsjzm.fPower = fPower;
                        objluggcsjzm.fnj = fForce * flics;
                        objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                        objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                        objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                        objluggcsjzm.dsxzxs = getKH();
                        objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                        objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                        objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                        objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                        objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        objluggcsjzm.GKLX = 1;
                        objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                        objluggcsjzm.fpowerK = fpowerK;
                        objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                        objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                        objluggcsjzm.nlxzxs = 1;
                        objluggcsjzm.nlxs = 1;
                       
                    }
                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    //   WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;


                    dstart = DateTime.Now;
                }

            }

            for (int i100 = 0; i100 < 12; i100++)
            {
                dstart = DateTime.Now;
                while (true)
                {//变化速度不能超过2KM/H/S
                    Thread.Sleep(100);
                   
                    sxianshineirong = string.Format(@"检测100点保持住...");
                    szhuantai = "100点检测";

                    sshanghang = string.Format(@"检测100点");
                    sxiahang = string.Format(@"油门保持住...");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                    float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                    float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                    fForce = fzou + fyou + fhou;
                    if (fForce < 0)
                    {
                        fForce = 0;
                    }

                    m_fgonglv = (m_fspeed * fForce * flics) / 360;

                    xianshixinxi();

                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                    fPower = (m_fspeed * fForce * flics) / 360;
                    if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                    {
                        if (zhongzhijiance())
                        {
                            m_mainform.DAC.PutVol(0);
                            sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                            xianshixinxi();
                            while (true)
                            {
                                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                                if (m_fspeed < 1)
                                {
                                    break;
                                }
                                Thread.Sleep(1000);
                            }
                            return false;

                        }

                        dstart = DateTime.Now;
                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_SKGCSJ100K[i100count] = m_mainform.objbtg.m_fsk;//100点K值

                        if (m_mainform.jzjskz.Contains("否"))
                        {
                            if (m_SKGCSJ100K[i100count] < 0.01)
                            {
                                m_SKGCSJ100K[i100count] = ((float)m_mainform.getRandom(1, 3)) / 100f;
                            }
                            if (i100count > 0 && m_SKGCSJ100K[i100count] == m_SKGCSJ100K[i100count - 1])
                            {
                                m_SKGCSJ100K[i100count] = m_SKGCSJ100K[i100count] + 0.01f;
                            }
                        }
                        m_SKGCSJ100NO[i100count] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJ100Speed[i100count] = m_fspeed;//100点速度
                        m_SKGCSJ100Power[i100count] = fPower;//100点功率
                        m_SKGCSJ100Turn[i100count] = izhuansu;//100点转速
                        m_SKGCSJ100Force[i100count] = fForce * flics;//100点加载力
                        m_SKGCSJ100youwen[i100count] = m_mainform.objbtg.m_fWenDu;//100点油温    问题
                      

                        m_SKGCSJ100wendu[i100count] = m_mainform.objbtg.m_fWenDu;
                        m_SKGCSJ100shidu[i100count] = m_mainform.objbtg.m_fShiDu;
                        m_SKGCSJ100daqiya[i100count] = m_mainform.objbtg.m_fYaLi;

                        m_SKGCSJ100PowerK[i100count] = fpowerK;//100点功率修正系数
                        m_SKGCSJ100Time[i100count] = DateTime.Now.ToString();//100点采样时间

                        //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        iobd = imaxcount;// +i100count;
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");


                        igksj[1]++;
                        i100count++;
                        inspectorNum = inspectorNum + 1;


                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "2";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压

                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间

                        imaxcount++;

                        VelMaxHP100End = imaxcount;

                        if (m_mainform.objbtg.m_fnosk > nox100)
                        {
                            nox100 = m_mainform.objbtg.m_fnosk;        //100%VelMaxHP 点NOx 值
                        }
                        zs100 = izhuansu;         //100%VelMaxHP 点发动机转速
                        zgxsd100 = m_fspeed;      //100%VelMaxHP 点转鼓线速度
                        lbgl100 = fPower;       //100%VelMaxHP 点轮边功率

                        //云景
                        //if (m_mainform.sconnetname.Contains("云景"))
                        {
                           
                            objluggcsjzm.ftrun = izhuansu;
                            objluggcsjzm.m_fspeed = m_fspeed;
                            objluggcsjzm.fPower = fPower;
                            objluggcsjzm.fnj = fForce * flics;
                            objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                            objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                            objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                            objluggcsjzm.dsxzxs = getKH();
                            objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                            objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                            objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                            objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                            objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            objluggcsjzm.GKLX = 2;
                            objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                            objluggcsjzm.fpowerK = fpowerK;
                            objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                            objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                            objluggcsjzm.nlxzxs = 1;
                            objluggcsjzm.nlxs = 1;
                           
                        }



                        sudu[ileng] = m_fspeed;
                        gl[ileng] = fPower;
                        f_sk[ileng] = m_mainform.objbtg.m_fsk;
                        //WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                        ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                        sgl[ileng] = string.Format(@"{0}", fPower);

                        WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                        ileng++;


                        break;


                    }
                }
            }
            m_mainform.objbass.GetPic("41");//安车拍照发送命令
            //
            float fsk = 0;
            float fsno = 0;
            for (int j = 0; j < 12; j++)
            {
                fsk = fsk + m_SKGCSJ100K[j];
                fsno = fsno + m_SKGCSJ100NO[j];
            }
            m_sk100 = fsk / 12;// 读取到数据以后复制给变量
            m_sno100 = fsno / 12;
            /////////////////////100点
            m_jgsk100 = m_sk100;
            d100k = m_jgsk100;
            xianshi100k();

            //测试80%转速的排放
            iwendingdianshu = 0;
            int i80count = 0;
            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
            //xianshiyibiao();
            sxianshineirong = string.Format(@"检测80%MaxHp排放速度{0:N1}", m_fspeed);
            xianshixinxi();
            sshanghang = string.Format(@"检测80%");
            sxiahang = string.Format(@"MaxHp速度{0:N1}", m_fspeed);
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

            VelMaxHP80Start = imaxcount + 1;
            //测试80%转速的排放
            setForc(fore80);//80点时候的输出

            DateTime dstart80 = DateTime.Now;
            while (true)//调整加载，然后稳定后测量开始。。。
            {
                Thread.Sleep(200);
                if (iwendingdianshu > 2)
                {
                    break;
                }
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;
                if (fForce < 0)
                {
                    fForce = 0;
                }

                sxianshineirong = string.Format(@"80点速度{0};当前{1}", (maxpowerspeed * 0.8).ToString("0.00"), m_fspeed.ToString("0.00"));
                szhuantai = "80点检测";


                sshanghang = string.Format(@"80点速度{0}", (maxpowerspeed * 0.8).ToString("0.00"));
                sxiahang = string.Format(@"当前{0}", m_fspeed.ToString("0.00"));
                m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);

                m_fgonglv = (m_fspeed * fForce * flics) / 360;

              
                if (m_mainform.DateDiff(DateTime.Now, dstart80) > 1000 * 8)
                {
                    break;
                }

                xianshixinxi();
                fPower = (m_fspeed * fForce * flics) / 360;


                if (m_mainform.DateDiff(DateTime.Now, dstart) > 1000)
                {
                    if (zhongzhijiance())
                    {
                        m_mainform.DAC.PutVol(0);
                        sxianshineirong = string.Format(@"CO2过低或温度超过40度 终止检测");
                        xianshixinxi();
                        while (true)
                        {
                            m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                            if (m_fspeed < 1)
                            {
                                break;
                            }
                            Thread.Sleep(1000);
                        }
                        return false;

                    }

                    dstart = DateTime.Now;
                    if (m_fspeed > fspeed80 - 1 && m_fspeed < fspeed80 + 1)
                    {
                        iwendingdianshu++;
                    }
                    else
                    {
                        iwendingdianshu = 0;
                    }
                    double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                    double dpow = Math.Pow(d1, 0.7);
                    fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                    double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                    double dpow11 = Math.Pow(d11, 0.7);
                    double dpow12 = Math.Pow(d1, 1.5);
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }

                   
                    iobd = imaxcount;// +i100count + i80count;
                    if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                    {
                        sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                        xianshixinxi();
                        return false;
                    }
                    OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                    OBD_fh[iobd] = m_mainform.OBD_fh;
                    OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                    OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                    OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                    OBD_cs[iobd] = m_mainform.OBD_cs;
                    OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                    OBD_jql[iobd] = m_mainform.OBD_jql;
                    OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                    OBD_scgl[iobd] = m_mainform.OBD_scgl;
                    OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                    OBD_hyl[iobd] = m_mainform.OBD_hyl;
                    OBD_no[iobd] = m_mainform.OBD_no;
                    OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                    OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                    OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                    OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                    OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                    OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");


                    igksj[2]++;
                    //i80count++;


                    float yali = 0;
                    if (m_mainform.objbtg.m_fYaLi > 0)
                    {
                        yali = m_mainform.objbtg.m_fYaLi;
                    }
                    fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                    //if(bwlzy)
                    {
                        fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                    }
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                    m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                    m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                    m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                    m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                    m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                    m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                    m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                    m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                    m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                    m_SKGCSJmaxjczt[imaxcount] = "5";
                    //m_mainform.gethuanjing();//读取数据库环境参数 

                    //m_mainform.objbtg.m_fWenDu
                    m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                    m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                    m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                    m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                    m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                    imaxcount++;


                    //云景
                    //if (m_mainform.sconnetname.Contains("云景"))
                    {
                        objluggcsjzm.ftrun = izhuansu;
                        objluggcsjzm.m_fspeed = m_fspeed;
                        objluggcsjzm.fPower = fPower;
                        objluggcsjzm.fnj = fForce * flics;
                        objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                        objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                        objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                        objluggcsjzm.dsxzxs = getKH();
                        objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                        objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                        objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                        objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                        objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                        objluggcsjzm.GKLX = 3;
                        objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                        objluggcsjzm.fpowerK = fpowerK;
                        objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                        objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                        objluggcsjzm.nlxzxs = 1;
                        objluggcsjzm.nlxs = 1;
                       
                    }



                    sudu[ileng] = m_fspeed;
                    gl[ileng] = fPower;
                    f_sk[ileng] = m_mainform.objbtg.m_fsk;
                    //  WriteGraphGCQX(zg, sudu, gl, f_sk, ileng);
                    ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                    sgl[ileng] = string.Format(@"{0}", fPower);

                    WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                    ileng++;
                    dstart = DateTime.Now;

                }
            }

            for (int i80 = 0; i80 < 12; i80++)
            {
                dstart = DateTime.Now;
                while (true)
                {//变化速度不能超过2KM/H/S
                    Thread.Sleep(200);
                   
                    sxianshineirong = string.Format(@"检测80点保持住...");
                    szhuantai = "80点检测";
                    sshanghang = string.Format(@"检测80点");
                    sxiahang = string.Format(@"油门保持住...");
                    m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);
                    m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);

                    m_fgonglv = (m_fspeed * fForce * flics) / 360;
                    xianshixinxi();

    
                    fPower = (m_fspeed * fForce * flics) / 360;
                    if ((DateTime.Now - dstart).TotalMilliseconds > 1000)
                    {

                        double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                        double dpow = Math.Pow(d1, 0.7);
                        fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                        double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                        double dpow11 = Math.Pow(d11, 0.7);
                        double dpow12 = Math.Pow(d1, 1.5);
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                        float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                        float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                        fForce = fzou + fyou + fhou;
                        if (fForce < 0)
                        {
                            fForce = 0;
                        }

                        fPower = (m_fspeed * fForce * flics) / 360;
                        m_SKGCSJ80K[i80count] = m_mainform.objbtg.m_fsk;//100点K值

                        if (m_mainform.jzjskz.Contains("否"))
                        {
                            if (m_SKGCSJ80K[i80count] < 0.01)
                            {
                                m_SKGCSJ80K[i80count] = ((float)m_mainform.getRandom(1, 3)) / 100f;
                            }
                            if (i80count > 0 && m_SKGCSJ80K[i80count] == m_SKGCSJ80K[i80count - 1])
                            {
                                m_SKGCSJ80K[i80count] = m_SKGCSJ80K[i80count] + 0.01f;
                            }
                        }
                        m_SKGCSJ80NO[i80count] = m_mainform.objbtg.m_fnosk;//
                        m_SKGCSJ80Speed[i80count] = m_fspeed;//100点速度
                        m_SKGCSJ80Power[i80count] = fPower;//100点功率
                        m_SKGCSJ80Turn[i80count] = izhuansu;//100点转速
                        m_SKGCSJ80Force[i80count] = fForce * flics;//100点加载力
                        m_SKGCSJ80youwen[i80count] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//100点油温    问题
                        //m_mainform.gethuanjing();//读取数据库环境参数 

                        m_SKGCSJ80wendu[i80count] = m_mainform.objbtg.m_fWenDu;//100点温度
                        m_SKGCSJ80shidu[i80count] = m_mainform.objbtg.m_fShiDu;//100点湿度
                        m_SKGCSJ80daqiya[i80count] = m_mainform.objbtg.m_fYaLi;//100点大气压
                        m_SKGCSJ80PowerK[i80count] = fpowerK;//100点功率修正系数
                        m_SKGCSJ80Time[i80count] = DateTime.Now.ToString();//100点采样时间

                        //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                        iobd = imaxcount;// +i100count + i80count;
                        if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                        {
                            sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                            xianshixinxi();
                            return false;
                        }
                        OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                        OBD_fh[iobd] = m_mainform.OBD_fh;
                        OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                        OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                        OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                        OBD_cs[iobd] = m_mainform.OBD_cs;
                        OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                        OBD_jql[iobd] = m_mainform.OBD_jql;
                        OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                        OBD_scgl[iobd] = m_mainform.OBD_scgl;
                        OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                        OBD_hyl[iobd] = m_mainform.OBD_hyl;
                        OBD_no[iobd] = m_mainform.OBD_no;
                        OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                        OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                        OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                        OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                        OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                        OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                        igksj[2]++;
                        i80count++;


                        float yali = 0;
                        if (m_mainform.objbtg.m_fYaLi > 0)
                        {
                            yali = m_mainform.objbtg.m_fYaLi;
                        }
                        fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                        //if(bwlzy)
                        {
                            fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                        }
                        m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                        m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                        m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                        m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                        m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                        m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                        m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                        m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                        m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                        m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                        m_SKGCSJmaxjczt[imaxcount] = "4";
                        //m_mainform.gethuanjing();//读取数据库环境参数 


                        m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                        m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                        m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                        m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                        m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                        imaxcount++;
                        VelMaxHP80End = imaxcount;

                        m_mainform.baocunrijiGCSJ(string.Format("{0}加载减速80过程数据日志", hphm.Text),
                          string.Format("K:{0},速度:{1},功率:{2},转速:{3},NOx:{4},油温:{5}",
                          m_mainform.objbtg.m_fsk, m_fspeed, fPower, izhuansu, m_mainform.objbtg.m_fnosk, (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK)));


                        zs80 = izhuansu;          //80%VelMaxHP 点发动机转速
                        zgxsd80 = m_fspeed;       //80%VelMaxHP 点转鼓线速度
                        lbgl80 = fPower;        //80%VelMaxHP 点轮边功率
                        //云景
                        //if (m_mainform.sconnetname.Contains("云景"))
                        {
                            objluggcsjzm.ftrun = izhuansu;
                            objluggcsjzm.m_fspeed = m_fspeed;
                            objluggcsjzm.fPower = fPower;
                            objluggcsjzm.fnj = fForce * flics;
                            objluggcsjzm.m_fsk = m_mainform.objbtg.m_fsk;
                            objluggcsjzm.m_fco2sk = m_mainform.objbtg.m_fco2sk;
                            objluggcsjzm.noxz = (float)(m_mainform.objbtg.m_fnosk * getKH());
                            objluggcsjzm.dsxzxs = getKH();
                            objluggcsjzm.m_fnosk = m_mainform.objbtg.m_fnosk;
                            objluggcsjzm.m_fWenDu = m_mainform.objbtg.m_fWenDu;
                            objluggcsjzm.m_fYaLi = m_mainform.objbtg.m_fYaLi;
                            objluggcsjzm.m_fShiDu = m_mainform.objbtg.m_fShiDu;
                            objluggcsjzm.m_fyouwenSK = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);
                            objluggcsjzm.GKLX = 4;
                            objluggcsjzm.m_fzgxsd = m_fspeed;// *((float)iedzs) / maxzhuansu;
                            objluggcsjzm.fpowerK = fpowerK;
                            objluggcsjzm.fpowerXZMAX = fPower * fpowerK;//问题
                            objluggcsjzm.fpowerSCMAX = fPower * fpowerK;//问题
                            objluggcsjzm.nlxzxs = 1;
                            objluggcsjzm.nlxs = 1;
                            
                        }



                        inspectorNum = inspectorNum + 1;

                        sudu[ileng] = m_fspeed;
                        gl[ileng] = fPower;
                        f_sk[ileng] = m_mainform.objbtg.m_fsk;
                      
                        ssudu[ileng] = string.Format(@"{0}", m_fspeed);
                        sgl[ileng] = string.Format(@"{0}", fPower);

                        WriteGraphEX(zg, ssudu, sgl, (double)(50), ileng);
                        ileng++;


                        break;
                    }
                }
            }

            bthread3 = true;
            m_mainform.objbass.GetPic("43");//安车拍照发送命令

            sxianshineirong = string.Format(@"检测结束,请勿制动");
            szhuantai = "请勿制动";
            Thread.Sleep(1000);
            sshanghang = string.Format("请松油门");
            sxiahang = string.Format("请勿制动");
            m_mainform.flowwq.LedWrite(sshanghang, sxiahang, 1);


            xianshixinxi();


            //
            fsk = 0;
            fsno = 0;
            for (int j = 0; j < 12; j++)
            {
                fsk = fsk + m_SKGCSJ80K[j];
                fsno = fsno + m_SKGCSJ80NO[j];
            }
            m_sk80 = fsk / 12;// 读取到数据以后复制给变量
            m_sno80 = fsno / 12;
            m_jgsk80 = m_sk80;
            d80k = m_jgsk80;
            xianshi80k();

            while (true)
            {
                m_fspeed = m_mainform.DAC.getjsz("测功速度", m_mainform.DAC.fTIData[iLUGSDtd]);
                float fzou = m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIData[iLUGtdz]) - m_mainform.DAC.getjsz("测功力左", m_mainform.DAC.fAIDataZero[iLUGtdz]);
                float fyou = m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIData[iLUGtdy]) - m_mainform.DAC.getjsz("测功力右", m_mainform.DAC.fAIDataZero[iLUGtdy]);
                float fhou = m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIData[iLUGtdh]) - m_mainform.DAC.getjsz("测功力后", m_mainform.DAC.fAIDataZero[iLUGtdh]);

                fForce = fzou + fyou + fhou;

                fPower = (m_fspeed * fForce * flics) / 360;
                xianshiyibiao();
                if (m_fspeed < 1)
                {
                    break;
                }
                Thread.Sleep(800);

                //m_mainform.getOBD_GCSJ(businessId);//读取OBD过程数据
                iobd = imaxcount;// +i100count + i80count;
                if (!m_mainform.getOBD_GCSJ(businessId))//读取OBD过程数据
                {
                    sxianshineirong = "找不到OBD过程数据，请接好OBD再上线！";
                    xianshixinxi();
                    return false;
                }
                OBD_jqmkd[iobd] = m_mainform.OBD_jqmkd;
                OBD_fh[iobd] = m_mainform.OBD_fh;
                OBD_qycgqxh[iobd] = m_mainform.OBD_qycgqxh;
                OBD_glkqxs[iobd] = m_mainform.OBD_glkqxs;
                OBD_ymkd[iobd] = m_mainform.OBD_ymkd;
                OBD_cs[iobd] = m_mainform.OBD_cs;
                OBD_fdjzs[iobd] = m_mainform.OBD_fdjzs;
                OBD_jql[iobd] = m_mainform.OBD_jql;
                OBD_jqyl[iobd] = m_mainform.OBD_jqyl;
                OBD_scgl[iobd] = m_mainform.OBD_scgl;
                OBD_zyyl[iobd] = m_mainform.OBD_zyyl;
                OBD_hyl[iobd] = m_mainform.OBD_hyl;
                OBD_no[iobd] = m_mainform.OBD_no;
                OBD_nsbsl[iobd] = m_mainform.OBD_nsbsl;
                OBD_pqwd[iobd] = m_mainform.OBD_pqwd;
                OBD_klbjqyc[iobd] = m_mainform.OBD_klbjqyc;
                OBD_egrkd[iobd] = m_mainform.OBD_egrkd;
                OBD_rypsyl[iobd] = m_mainform.OBD_rypsyl;
                OBD_sjxl[iobd] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");

                //igksj[2]++;
                //i80count++;

                double d1 = (m_mainform.objbtg.m_fWenDu + 273) / 298;
                double dpow = Math.Pow(d1, 0.7);
                fpowerK = (99 / m_mainform.objbtg.m_fYaLi) * dpow;//对自然吸气式和机械增压发动机
                double d11 = (99 / m_mainform.objbtg.m_fYaLi);
                double dpow11 = Math.Pow(d11, 0.7);
                double dpow12 = Math.Pow(d1, 1.5);
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }

                float yali = 0;
                if (m_mainform.objbtg.m_fYaLi > 0)
                {
                    yali = m_mainform.objbtg.m_fYaLi;
                }
                fpowerK = (99 / yali) * dpow;//对自然吸气式和机械增压发动机
                //if(bwlzy)
                {
                    fpowerK = dpow11 * dpow12;//对涡轮增压或涡轮增压中冷发动机
                }

                m_SKGCSJmaxK[imaxcount] = m_mainform.objbtg.m_fsk;//max点K值
                m_SKGCSJmaxN[imaxcount] = m_mainform.objbtg.m_fnssk;
                m_SKGCSJmaxNO[imaxcount] = m_mainform.objbtg.m_fnosk;
                m_SKGCSJmaxSpeed[imaxcount] = m_fspeed;//max点速度
                m_SKGCSJmaxPower[imaxcount] = fPower;//max点功率
                m_SKGCSJmaxTurn[imaxcount] = izhuansu;//max点转速
                m_SKGCSJmaxForce[imaxcount] = fForce * flics;//max点加载力
                m_SKGCSJmaxyouwen[imaxcount] = (byw ? fywrg : m_mainform.objbtg.m_fyouwenSK);//max点油温    问题

                m_SKGCSJmaxco2[imaxcount] = m_mainform.objbtg.m_fco2sk;
                m_SKGCSJmaxjczt[imaxcount] =m_mainform.sconnetname.Contains("智慧")?"5":"0";
                //m_mainform.gethuanjing();//读取数据库环境参数 


                m_SKGCSJmaxwendu[imaxcount] = m_mainform.objbtg.m_fWenDu;//max点温度
                m_SKGCSJmaxshidu[imaxcount] = m_mainform.objbtg.m_fShiDu;//max点湿度
                m_SKGCSJmaxdaqiya[imaxcount] = m_mainform.objbtg.m_fYaLi;//max点大气压
                m_SKGCSJmaxPowerK[imaxcount] = fpowerK;//max点功率修正系数
                m_SKGCSJmaxTime[imaxcount] = DateTime.Now.ToString();//max点采样时间
                imaxcount++;
            }

            m_mainform.DAC.PutVol(0);

            DateTime dtdszs = DateTime.Now;
            while (true)//
            {
                if (btgds1min)
                    break;
                if (DateTime.Now > dtdszs.AddSeconds(60))
                    break;
                sxianshineirong = string.Format("记录怠速转速{0}秒", Math.Round(60 - ((DateTime.Now - dtdszs).TotalSeconds)).ToString("0"));
                xianshixinxi();
                xianshizhuansu();
                Thread.Sleep(500);
            }
            Thread.Sleep(500);
            m_mainform.DAC.Lift(true);


            //上传结果
            timeEnd = DateTime.Now.ToLocalTime().ToString();
            if (m_mainform.TypeApprovalLimits == 0)
            {
                m_mainform.TypeApprovalLimits = 1.2f;

            }

            bgood = true;
            if (m_sk100 > m_mainform.TypeApprovalLimits || m_sk80 > m_mainform.TypeApprovalLimits || fFindMaxPower < ((double)iedgl) * 0.4 || m_sno80 > m_mainform.noxlimit)
            {
                bgood = false;
            }
            if (m_sno80 < 1)
            {
                m_sno80 = 35;
            }
            string sql = string.Format(@"update Detects_SJE set 
                                                ER1={0},
                                                ER2={1},
                                                ER3={2},
                                                SKTrun={3},
                                                SKPower={4},
                                                GasWenDu={5},
                                                GasShiDu={6},
                                                GasYaLi={7},
                                                Time_begin='{8}',
                                                Time_end='{9}',
                                                ERNO1={10},
                                                ERNO3={11},
                                                velmaxhp={12},
                                                WQPD={13}
                                                where DETECT_ID={14}  or ASM_JYLSH='{14}' ",
                                                m_sk100,
                                                m_sk90,
                                                m_sk80,
                                                maxpowertrun,
                                                fFindMaxPower,
                                                fwendu,
                                                fshidu,
                                                fdaqiya,
                                                timeStart,
                                                timeEnd,
                                                m_sno100,
                                                m_sno80,
                                                maxpowerspeed,
                                                bgood ? 1 : 2,
                                                businessId);
            m_mainform.objbass.objdb.InsertDB(sql);

            // 保存过程数据到本地数据库
            baocunGCSJ_LUG(businessId, m_mainform.testtimes);
            baocunGCSJ_OBD(businessId);
            // 保存过程数据到本地数据库
            //上传数据

            //录像结苏
            #region 安车
            //if (m_mainform.sconnetname.Contains("安车"))
            if(false)
            {
                //长沙安车平台
                //过程数据

                string cysx = "";
                string btgclz = "";
                string cs = "";
                string zs = "";
                string jzgl = "";
                string gxsxs = "";
                string zsgl = "";
                string yw = "";
                string glxzxs = "";
                string jsgl = "";
                string btgd = "";
                string dqyl = "";
                string xdsd = "";
                string hjwd = "";
                string sjxl = "";
                string nl = "";
                string jczt = "";
                string noxclz = "";
                string co2clz = "";
                string jcsj = "";
                string gksj = "";
                jcsj = (igksj[0] + igksj[1] + igksj[2]).ToString();
                gksj = string.Format("{0},{1},{2}", igksj[0], igksj[1], igksj[2]);
                for (int i = 0; i < imaxcount; i++)
                {
                    if (i == 0)
                    {

                        cysx = string.Format(@"{0}", i + 1);
                        btgclz = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        noxclz = string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                        cs = string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                        zs = string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                        jzgl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                        gxsxs = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        zsgl = string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                        yw = string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                        glxzxs = string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                        jsgl = string.Format(@"{0}", 0.5);
                        btgd = string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        dqyl = string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                        xdsd = string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                        hjwd = string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                        sjxl = string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                        nl = string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                        jczt = string.Format(@"{0}", m_SKGCSJmaxjczt[i]);
                        co2clz = string.Format(@"{0}", m_SKGCSJmaxco2[i]);
                    }
                    else
                    {
                        cysx = cysx + "," + string.Format(@"{0}", i + 1);
                        btgclz = btgclz + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        noxclz = noxclz + "," + string.Format(@"{0}", m_SKGCSJmaxNO[i]);
                        cs = cs + "," + string.Format(@"{0}", m_SKGCSJmaxSpeed[i]);
                        zs = zs + "," + string.Format(@"{0}", m_SKGCSJmaxTurn[i]);
                        jzgl = jzgl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxPower[i]));
                        gxsxs = gxsxs + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        zsgl = zsgl + "," + string.Format(@"{0}", m_SKGCSJmaxPower[i]);
                        yw = yw + "," + string.Format(@"{0}", m_SKGCSJmaxyouwen[i]);
                        glxzxs = glxzxs + "," + string.Format(@"{0}", m_SKGCSJmaxPowerK[i].ToString("0.0"));
                        jsgl = jsgl + "," + string.Format(@"{0}", 0.5);
                        btgd = btgd + "," + string.Format(@"{0}", m_SKGCSJmaxK[i]);
                        dqyl = dqyl + "," + string.Format(@"{0}", m_SKGCSJmaxdaqiya[i]);
                        xdsd = xdsd + "," + string.Format(@"{0}", m_SKGCSJmaxshidu[i]);
                        hjwd = hjwd + "," + string.Format(@"{0}", m_SKGCSJmaxwendu[i]);
                        sjxl = sjxl + "," + string.Format(@"{0}", m_SKGCSJmaxTime[i]);
                        nl = nl + "," + string.Format(@"{0}", Math.Abs(m_SKGCSJmaxForce[i]));
                        jczt = jczt + "," + string.Format(@"{0}", m_SKGCSJmaxjczt[i]);

                        co2clz = co2clz + "," + string.Format(@"{0}", m_SKGCSJmaxco2[i]);
                    }
                }

                string vehispara = "";
                string stoubao = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
                stoubao = stoubao + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                               m_mainform.organ,
                                                              m_mainform.jkxlh,
                                                               "GC004");
                vehispara = stoubao + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <cyds>{2}</cyds>
                                <cysx>{3}</cysx>
                                <cs>{4}</cs>
			                    <zs>{5}</zs>
			                    <jzgl>{6}</jzgl>
			                    <gxsxs>{7}</gxsxs>
			                    <zsgl>{8}</zsgl>
			                    <yw>{9}</yw>
			                    <glxzxs>{10}</glxzxs>
			                    <jsgl>{11}</jsgl>
			                    <btgd>{12}</btgd>
			                    <dqyl>{13}</dqyl>
			                    <xdsd>{14}</xdsd>
			                    <hjwd>{15}</hjwd>
                                <sjxl>{16}</sjxl>
                                <nl>{17}</nl>
                                <jczt>{18}</jczt>
                                <btgclz>{19}</btgclz>
                                <noxclz>{20}</noxclz>
                                <co2clz>{21}</co2clz>
                                <jcsj>{22}</jcsj>
<gksj>{23}</gksj>
</vehispara>
</body>
</root>",
 businessId,
 m_mainform.testtimes,
 imaxcount,
 cysx,
 cs,
 zs,
 jzgl,
 gxsxs,
 zsgl,
 yw,
 glxzxs,
 jsgl,
 btgd,
 dqyl,
 xdsd,
 hjwd,
 sjxl,
 nl,
 jczt,
 btgclz,
 noxclz,
 co2clz,
 jcsj,
 gksj);



                obdsc();//发送OBD过程数据
                WebReferenceCS.VeptsOutAccess m_vesd = new WebReferenceCS.VeptsOutAccess();
                m_vesd.Url = m_mainform.surl;

                string sgc005 = m_mainform.decode(m_vesd.write(vehispara));
                if (!sgc005.ToUpper().Contains("<CODE>1</CODE>"))
                {
                    //m_mainform.baocunriji(string.Format("过程数据:{0}", m_mainform.decode(sgc005)));
                    //m_mainform.baocunrijiJGLUG(vehispara);
                    m_mainform.baocunRJ("LUG过程数据", vehispara); //
                    m_mainform.baocunRJ("LUG过程数据结果", m_mainform.decode(sgc005)); //
                    sxianshineirong = "上传过程数据失败 ";
                    xianshixinxi();
                }

                //过程数据

                //检测结果
                bgoodpf = true;
                if (m_sk100 > m_mainform.TypeApprovalLimits || m_sk80 > m_mainform.TypeApprovalLimits)
                {
                    bgoodpf = false;
                }

                string vehisparajg = "";
                string stoubaojg = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
                stoubaojg = stoubaojg + string.Format(@"<root><head><organ>{0}</organ><jkxlh>{1}</jkxlh><jkid>{2}</jkid></head>",
                                                         m_mainform.organ,
                                                        m_mainform.jkxlh,
                                                         "JC004");
                vehisparajg = stoubaojg + string.Format(@"<body><vehispara>
                                <jylsh>{0}</jylsh>
                                <testtimes>{1}</testtimes>
                                <wd>{2}</wd>
                                <dqy>{3}</dqy>
                                <xdsd>{4}</xdsd>
			                    <velmaxhp>{5}</velmaxhp>
			                    <rev100>{6}</rev100>
			                    <maxpower>{7}</maxpower>
			                    <maxpowerlimit>{8}</maxpowerlimit>
			                    <zdlbglzs>{9}</zdlbglzs>
			                    <zdlbgljudge>{10}</zdlbgljudge>
			                    <smokeklimit>{11}</smokeklimit>
			                    <ydjudge>{12}</ydjudge>
			                    <k100>{13}</k100>
			                    <k80>{14}</k80>
                                <nox>{15}</nox>
                                <noxlimit>{16}</noxlimit>
                                <raterevup>{17}</raterevup>
                                <raterevdown>{18}</raterevdown>
                                <result>{19}</result>
                                 </vehispara>
			                    </body>
                                </root>",
                                   businessId,
                                   m_mainform.testtimes,
                                    fwendu.ToString("0.00"),
                                    fdaqiya.ToString("0.00"),
                                    fshidu.ToString("0.00"),
                                   maxpowerspeed.ToString("0.00"),
                                   trunMax,
                                    fFindMaxPower.ToString("0.0"),
                                   0.4f * ((float)iedgl),
                                   trunMax,
                                   fFindMaxPower < (((float)iedgl) * 0.4f) ? 0 : 1,
                                   m_mainform.TypeApprovalLimits,
                                   bgoodpf ? 1 : 0,
                                   m_sk100.ToString("0.00"),
                                    m_sk80.ToString("0.00"),
                                    m_sno80.ToString("0.00"),
                                    m_mainform.noxlimit,
                                   iBiaoDingZhuanShu * 0.75f,
                                   iBiaoDingZhuanShu * 1.25f,
                                    bgood ? 1 : 0);
                string sjg005 = m_mainform.decode(m_vesd.write(vehisparajg));
                if (!sjg005.ToUpper().Contains("<CODE>1</CODE>"))
                {
                    m_mainform.baocunRJ("LUG结果数据", vehisparajg); //
                    m_mainform.baocunRJ("LUG结果数据结果", m_mainform.decode(sgc005)); //
                    sxianshineirong = "上传数据失败 ";
                    xianshixinxi();

                }


                m_mainform.sendjieshuAC(string.Format("{0}", bgood ? 1 : 0));//发送结束
            }
            #endregion
            else//云景的联网
            {
                bfh = senlwyj();
            }
            if (bfh)
            {
                m_mainform.objbass.insertjcwc(businessId);
                m_mainform.insertjcwc(businessId);
                m_mainform.objbass.stop(businessId, bgood ? "1" : "0");
            }

            if (bgood)
            {
                m_mainform.flowwq.LedWrite("尾气排放检测", "合格", 1);
                sxianshineirong = string.Format(@"尾气排放合格");
                xianshixinxi();
            }
            else
            {
                m_mainform.flowwq.LedWrite("尾气排放检测", "不合格", 1);
                sxianshineirong = string.Format(@"尾气排放不合格");
                xianshixinxi();
            }
            Thread.Sleep(3000);
            m_mainform.flowwq.LedWrite("尾气排放检测", "", 1);


            thisclose();

            return true;
        }

        public bool setForc(float Forc)
        {


            float data = 0;

            data = m_mainform.DAC.getcyz("涡流输出", Forc);

            m_mainform.DAC.PutVol(data);
            return true;
        }
        public double getKH()
        {
            //double dKH = 0;
            //double Ra = m_mainform.objbtg.m_fShiDu;
            //double Pd = Math.Pow(10, 7.07406 - (1657.46 / (227.02 + m_mainform.objfqy.m_fWenDu))); //饱和蒸气压 4.24;// 4132.982;//饱和蒸气压
            //double Pb = m_mainform.objfqy.m_fYaLi;
            //double ftest = (Pb - (Pd * Ra / 100));
            //double ftest2 = 6.2111 * Ra * Pd;
            //double H = (6.2111 * Ra * Pd / ((Pb - (Pd * Ra / 100)) > 0 ? (Pb - (Pd * Ra / 100)) : 1));
            //dKH = (((1 / ((1 - 0.0329 * (H - 10.7)) > 0 ? (1 - 0.0329 * (H - 10.7)) : 1))) * 100) * 0.01;
            //dKH = Math.Round(dKH, 2);

            float Ra = m_mainform.objbtg.m_fShiDu;
            double Pd = Math.Pow(10, 7.07406 - (1657.46 / (227.02 + m_mainform.objbtg.m_fWenDu))); //饱和蒸气压
            double Pb = m_mainform.objbtg.m_fYaLi;
            double H = (6.2111 * Ra * Pd / ((Pb - (Pd * Ra / 100)) > 0 ? (Pb - (Pd * Ra / 100)) : 1));
            double k = 1 / (1 - 0.0329 * (H - 10.71));
            k = Math.Round(k, 2);
            return k;
        }
        bool bbtgco2 = false;
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (m_mainform.stationCode.Contains("5201"))//驰安鹏达
            {
                bbtgco2 = true;
            }
        }

    }
}
